Including header in base.twig for all pages

Viewed 30

It is something pretty simple to be done outside of twig but here I am not even sure it is possible. This is the case: Have base.html.twig. header.html.twig, home.html.twig.

#home.html.twig
{% extends 'base.html.twig' %}

{% block body %}
    <h1>MY HTML</h1>
{% endblock %}


#base.html.twig
....some html here
{% block header%}{% endblock %}
{% block body %}{% endblock %}
....some more html here


#header.html.twig
{% extends 'base.html.twig' %}
{% block header %}
    some here things that have to shown on every page through base.html.twig
{% endblock %}

I think it is pretty straight forward scenario but still my header doesn't show anywhere. As I understood from the documentation it is not working because this is how blocks work. It renders the page i am calling from my controller (home.html.twig) and the extended by it (base.html.twig). But wont call the header as well. So! How should I call the header on every page ?

1 Answers

To add the header on all pages just put include see example

{% block header %}
    {% include 'header.html.twig' %}
{% endblock %}
Related