0

ヘッダー、コンテンツ、フッターの 3 つのブロックのみを含む symfony2 で基本レイアウトを整理することを考えています。そして、ブロックごとに 1 つのテンプレートが必要です。「コンテンツ」テンプレートは、「3 レベル」ディレクティブに従って、すべてのセクションのテンプレートのみを表示する空のテンプレートになります。しかし、ヘッダーとフッターのテンプレートを含める方法がわかりません。「バイパス」テンプレートを作成したので、たとえば、コンテンツはフッターを拡張し、フッターはヘッダーを拡張し、ヘッダーはベースを拡張しますが、見た目が非常に悪いです。ありがとう。

4

2 に答える 2

4

include と extends の動作を組み合わせたembedタグを使用できます。include と同様に、別のテンプレートのコンテンツを含めることができます。ただし、テンプレートを拡張するときのように、含まれているテンプレート内で定義されたブロックをオーバーライドすることもできますが、バージョン 1.8 が必要です

埋め込みタグ

于 2012-06-03T11:29:21.960 に答える
3

You can't extend more than one template in Twig, it is illogical anyway.
You should use include, which is a bit different.

The common way is to have one base template, which will be extended by all the other ones, except the header and the footer that will be included in it.

base.html.twig:

...
<body>
    {% include '::header.html.twig' %}
    {% block body %}{% endblock %}
    {% include '::footer.html.twig' %}
</body>
...

In the other templates, your bundles' views for example:

{% extends '::base.html.twig' %}

{% block body %}
Hello world!
{% endblock %}
于 2012-06-03T10:58:42.300 に答える