Symfony2 - 在twig中使用autoescape false不适用于{{include}}

时间:2014-06-15 02:41:56

标签: symfony twig

我试图在Twig中使用autoescape false作为索引页面中的段落间距,但是无论autoescape设置为false,它都不会显示空格。

有没有办法在include上使用autoescape false来显示段落间距?

不起作用:(不显示间距)

{% for post in posts %}
    {% autoescape false %}
        {{ include('AcmeDemoBundle:Page:_post.html.twig', { post: post }) }}
    {% endautoescape %}
{% endfor %}

当我在展示页面中使用它时效果很好:

<div class="entry-content">
    {% autoescape false %}
        <p>{{ post.body|truncate(2000) }}</p>
    {% endautoescape %}
</div>

1 个答案:

答案 0 :(得分:0)

autoescape标记与所包含的子模板没有范围。

  

[你]只能标记要转义的模板部分。

您需要在每个包含的子模板中定义自动转换 http://twig.sensiolabs.org/doc/tags/autoescape.html