php - Twig: How to set title in nested template blocks?
I have a twig structure like this:
{% extends '@layouts/default.html.twig' %}
{% block headerBar %}
{% include 'partials/my-navigation.html.twig' %}
{% endblock %}
{% block content %}
some content
{% endblock %}
But now I have always the same title in my "my-navigation.html.twig".
How can i make it dynamically? maybe something like this:
{% extends '@layouts/default.html.twig' %}
{% block myNiceTitle %}
COOL TITLE
{% endblock %}
{% block headerBar %}
{% include 'partials/my-navigation.html.twig' %}
{% endblock %}
{% block content %}
some content
{% endblock %}
and then i would use my title in the "my-navigation.html.twig" file dynamically? but how?
I have already read the manual here:
https://twig.symfony.com/doc/2.x/functions/block.html
but it doenst make me smarter :(
Thx for any hints
Answer
Solution:
Assuming that
myNiceTitle
is a block in your navigation template, you could useembed
and do something like:And somewhere in
partials/my-navigation.html.twig
:Answer
Solution:
Set a variable before the include
Then use it inside your include