【问题标题】:Include a template which is in the web folder包括一个位于 web 文件夹中的模板
【发布时间】:2013-12-30 22:46:57
【问题描述】:

我正在创建一个网站,让人们可以在其中上传自己的树枝模板。这些模板文件存储在 web 文件夹中。

如何在另一个模板中包含其中一个文件。

我试过了:

{% include dirname(__FILE__) ~ '/../../../../web/designs/' ~ target.design.filekey ~ '/DesignKit/design.html.twig' %}

但我收到一条错误消息,提示 dirname 函数不存在。

感谢您的帮助:)

【问题讨论】:

    标签: symfony twig


    【解决方案1】:

    使用:

    {% include '@web_dir/build/templates/templates.html.min.twig' %}
    

    # config.yml
    twig:
        paths:
            "%kernel.root_dir%/../web": web_dir
    

    【讨论】:

      【解决方案2】:

      你不能在 twig 中使用 php 语法。您可以使用 Web 目录的路径创建 global variable

      twig:
          # ...
          globals:
              web_dir: %kernel.root_dir%/../web
      

      您也可以重复使用asset function

      【讨论】:

        猜你喜欢
        • 2010-10-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多