首页 文章

在Twig中嵌入的路径不能包含变量,否则返回Variable not found错误

提问于
浏览
1

出于某种原因,设置变量以表示文件路径,然后使用它来嵌入不起作用 . 有谁知道原因?

这有效:

{% embed 'Console::components/somecomponent' with {} only %}
{% endembed %}

但这不是:

{% set abc = 'Console::components/somecomponent' %}
{% embed abc with {} only %}
{% endembed %}

以上返回以下错误:

第5行的“XXXXXX”中不存在变量“abc” .


另一方面,具有讽刺意味的是,“包括”似乎如下工作:

{% set abc = 'Console::components/anothercomponent' %}
{% include abc with {} only %}

如果有人能够给我一些启示,我将非常感激 .

谢谢!

1 回答

  • 1

    这里的问题是“唯一的”!

    将起作用的是:

    {% set abc = 'Console::components/somecomponent' %}
    {% embed abc with {} %}
    {% endembed %}
    

    要么:

    {% set abc = 'Console::components/somecomponent' %}
    {% embed abc %}
    {% endembed %}
    

相关问题