I do html/css by trade, and I have been working on and off django projects as a template designer. I'm currently working on a site that uses Jinja2, which I have been using for about 2 weeks. I just found out through reading the documentation that Jinja2 doesn't support multiple level template inheritance, as in you can't do more than one
{% extends "foo" %}
per rendering. Now I'm pretty sure you can do this in Django, which is powerful because you can specify a base template, specify 3 or 4 templates based on that, and then build the meat of your pages using those base templates. Isn't the point of inheritance so you have more power to abstract so your only really messing with unique code?
In any case I have no idea what to do here. I don't know if there is some way I can do it that will work as well as it could with the Django templates. I'm not exactly an expert at either Django or Jinja(2) but I can provide any information needed.
The way the documentation worded it, it seemed like it didn't support inheritance (n) levels deep.
I didn't know it was just a rule saying 1 extends per template.... I now know, with some help from the jinja irc channel.
I recently faced the same issue. I wanted to inherit several child templates and it worked. To illustrate it I would like to show you a solution that worked for me:
I had a base.html file that has block content and extended by manage.html. and that manage.html has a block sub_manage which is extended by internet_market.html, so visually it looks like:
when I rendered it, everythink worked fine, which means that you can have several {% extends %} in one render. the only thing is that if you are using relative links to your css or js files then it might not work, rather it will render, but it won't find your css/js files. like:
In that case you have to use dynamic links by using url_for. like:
See the documentation extending, including, and importing.
This provides the means of getting functionality from multiple files for different purposes and is different from the depth of the nesting. You can perfectly have a template that extends a template that extends a template...
You could use the following way to combine different contents into a single layout.html for various layout designs:
...and call:
in python code.
Try this, this work for me thanks to @Ixm answer.
base.html
content.html
footer.html
and call with
One of the best way to achieve multiple level of templating using jinja2 is to use 'include' let say you have 'base_layout.html' as your base template
and then you want to have 'child_layout.html' that extends 'base_layout.
and now your page can just extends 'child_layout.html' and it will have both base_layout.html and child_layout.html