代码之家  ›  专栏  ›  技术社区  ›  Thomas Cheng

嵌入细枝的路径不能包含变量,否则返回“找不到变量”错误

  •  1
  • Thomas Cheng  · 技术社区  · 6 年前

    出于某种原因,设置一个变量来表示一个文件路径,然后使用它来嵌入是行不通的。有人知道原因吗?

    这工作:

    {% 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 回复  |  直到 6 年前
        1
  •  1
  •   Basti    6 年前

    这里的问题是“唯一”!

    有效的方法是:

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

    或:

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