Is it possible to perform Includes with flask?
42,512
By default, Flask uses Jinja2 as its template engine. See Jinja's Template Designer Documentation how it's done.
Author by
Michael
Updated on July 09, 2022Comments
-
Michael almost 2 years
Say I have a template layout saved in template.html. This template includes a banner, side navigation, content container, and footer. Can I use flask to break up these page elements in such a way that I can have files such as banner.html, sidenavigation.html, etc. and render these different files within template.html?
-
jOSe over 3 yearsBut is it possible to highlight, which page is active in sidenavigation.html?
-
John Crawford about 2 years@jOSe You can make use of the
scoped
keyword in theblock
definition within "sidenavigation.html". See Jinja's "Block Nesting and Scope" section. Their example is{% block loop_item scoped %}{{ item }}{% endblock %}
which allowsitem
to pull its definition from the inheriting template.