N
N
NibiruanChild2018-08-22 09:20:43
Jinja
NibiruanChild, 2018-08-22 09:20:43

What is the proper way to layer a basic jinja2 template (Flask/Django)?

Hello.
I break the base template (which is inherited by other templates) into functional parts (layers/layouts). It looks roughly like this:
base.html

<html>
<head>
    {% include 'layouts/head.html'%}
</head>

<body>
    {% include 'layouts/navbar.html'%}

    <div class="container">
        <div class="row">
            <div class="col-12">
                <h1>{% block title %}{% endblock %}</h1>
                {% block content %}{% endblock %}
            </div>
        </div>
    </div>

    {% include 'layouts/footer.html'%}
    {% include 'layouts/js.html'%}
</body>
</html>

layouts/head.html
...
<title> {% block title %}{% endblock %}</title>
...

Similar
to layouts/navbar.html
layouts/footer.html
layouts/js.html
etc.
And here I have 2 problems:

1. title is not displayed if it is set in a layer added via include (a similar construction in one file, without splitting into layouts is fine works). This worked great in Laravel, but now I'm in a stupor.
2. how do i use block title twice (as title and as h1)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question