extends from twig

1

I am starting to use smfony and I have some doubts, I have the following base template:

base.html.twig

<!DOCTYPE html>
<html>
    <head>
        {% block head %}
            <meta charset="UTF-8">
            <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet">
            <title>{% block title %}Icebird{% endblock %}</title>
            {% block stylesheets %}{% endblock %}
        {% endblock %}
    </head>
    <body>
        {% block header %}Esto es un Header{% endblock %} 
        {% block nav %}Aqui hay una barra de navegación{% endblock %}
        {% block body %}{% endblock %}
        {% block footer %}Aqui hay un footer{% endblock %}
        {% block javascripts %}{% endblock %}
    </body>
</html>

I would like to have the code inside the block of header, nav and footer in another file since it is quite extensive and I would like to have it sorted, I am trying to create a file header.html.twig and there to put the code, then do a extends in base and include the labels of the header ( {% block header %}{% endblock %} ) in base but I get an error, some idea of how to do it?

    
asked by Ricardo Alvarado 11.06.2018 в 01:57
source

1 answer

2

What I usually do for this is to put all those template files in a directory inside templates (for example includes) and call from the frontend.html.twig to each of them:

{% block header %}
   {{ include("includes/header.html.twig") }}
{% endblock %}
{% block navbar %}
   {{ include("includes/navbar.html.twig") }}
{% endblock %}
{% block footer %}
   {{ include("includes/footer.html.twig") }}
{% endblock %}
    
answered by 11.06.2018 / 12:11
source