TWIG YII how to redeclare block from included file
I've got this kind of structure:
layout.twig:
{% include header.twig %}
{% block block1 %}
{% endblock %}
header.twig:
{% block block2 %}
{% endblock %}
index.twig:
{% extends "layout.twig" %}
{% block block1 %} text for block 1 {% endblock %}
{% block block2 %} text for block 2 {% endblock %}
When i'm rendering index.twig block1 is replaced with text value, as expected, but block2 remains empty. Why block2 isn't replaced by redeclared content? Is it correct for TWIG in common or it is a problem of TWIG implementation for Yii Framework only? How should i change the structu开发者_Go百科re to make it work as described?
Thanks in advance)
It's just because of the structure, the usual way is to have a root block in the layout, and override some blocks in templates.
layout.twig:
{% block body %}
{% block block2 %}
{% include header.twig %}
{% endblock %}
{% block block1 %}default text for block 1
{% endblock %}
{% endblock %}
header.twig:
default text for block 2
index.twig:
{% extends "layout.twig" %}
{% block block1 %} text for block 1 {% endblock %}
{% block block2 %} text for block 2 {% endblock %}
output:
text for block 1
text for block 2
精彩评论