Twig包括渲染两个时间块

时间:2014-04-30 10:37:42

标签: html symfony twig

我对Twig有些麻烦。我不明白为什么我的一个块在我的页面中渲染了两次。

A-propos.html.twig

{% extends "::layout-v2.html.twig" %}

{% set contexte = "a-propos" %}
{% block content %}
//some stuff
 {% block rightbar %}
            {{"Je suis dans le block de la vue rightbar"}}
            {{ parent() }}
 {% endblock %}
//some stuff
{% endblock %}

布局v2.html.twig

{% include '::header/header-v2.html.twig' %}

<body class="">
{% block topBar %}
{% endblock %}

{% if app.user %}
    {% include '::layout-user-v2.html.twig' with {'view_content': block('content')} %}
{% else %}
    {% include '::layout-public-v2.html.twig' with {'view_content': block('content')} %}
{% endif %}


{% block rightbar %}
<div class="col-sm-3">
    {% if contexte is defined %}
            {% include 'BtpGeneralBundle:Sidebars:sidebar_contexte.html.twig' %}
        {% else %}
            {% include 'BtpGeneralBundle:Sidebars:sidebar_default.html.twig' %}
    {% endif %}
</div>
{% endblock %}

{% include '::footer/footer-js-v2.html.twig' %}

</body>

我不明白为什么视图sidebar-context.html.twig第一次在正确的位置呈现,而另一次在包含脚注-js之前...

感谢

1 个答案:

答案 0 :(得分:1)

您可以在 A-propos.html.twig 中拆分 {%block content%} 两部分,例如在右栏 contetn2 之前 contetn1