Reputation: 1478
I've looked for resolving issue, that was asked in this question. https://github.com/fabpot/Twig/issues/1244
But for me, somehow that does not work...
#layout.html.twig
{{ show }}
#base1.html.twig
{% extends 'layout.html.twig' %}
{% set show = 0 %}
#base2.html.twig
{% extends 'base1.html.twig' %}
{% set show = 1 %}
But when i render base2, i see only 0 ... Why it is not 1 ?
Upvotes: 4
Views: 13006
Reputation: 620
Works perfectly for me. I guess it’s a block problem. Maybe your base1's block appears after the base2's one and overrides the value.
The problem would appear with this code for example:
#base2.html.twig
{% extends 'base1.html.twig' %}
{% block content %}
{% set show = 1 %}
{{ parent() }}
{{ show }}
{% endblock %}
You should try this:
#layout.html.twig
{% block content %}
{% set show = 0 %}
{{ show }}
{% endblock %}
#base1.html.twig
{% extends 'layout.html.twig' %}
{% block content %}
{{ parent() }}
{% set show = 1 %}
{{ show }}
{% endblock %}
#base2.html.twig
{% extends 'base1.html.twig' %}
{% block content %}
{{ parent() }}
{% set show = 2 %}
{{ show }}
{% endblock %}
Displaying show
variable at each step of the inheritance process, should help you to see what’s going wrong. The final response should display 0 1 2
.
Upvotes: 2