4

我想在我的视图中包含一个模板,但它不起作用,我有这个错误:

在第 46 行的 ::base.html.twig 中找不到模板“::StyleBlock/light-pattern.html.twig”。

我的代码:

{% for zone in content.blocks %}
    {% set path = '::StyleBlock/' ~ zone.styles %}
    {% include path %}
{% endfor %}

在详细信息中,我有此消息:

InvalidArgumentException:文件“views/StyleBlock/light-pattern.html.twig”不存在(在:/var/www/gathena/app/Resources)。

但是路径是正确的,我不明白。

我使用 Symfony 2.3 并且我对我的目录有很好的权限

4

2 回答 2

7

你给出了错误的路径,它应该是:

{% for zone in content.blocks %}
    {% set path = 'CmsCmsBundle:StyleBlock:' ~ zone.styles %}
    {% include path %}
{% endfor %}

至于路径src/Cms/CmsBundle/Resources/views/StyleBlock/

The first parameter is your bundle, second is the controller in this case StyleBlock, so your views are in your bundle in Resources/views/StyleBlock directory, last parameter is the template name which is defined by your loop variable in this case. It should only be your template name, without any absolute paths. All parameters are seperated by :

于 2013-08-03T14:01:35.563 回答
0

试试这个 :

::StyleBlock:light-pattern.html.twig
于 2013-08-03T13:36:44.583 回答