decitrig
decitrig

Reputation: 788

Django template include/extend with subdirectories

Considering the following directory:

|- basic.html
|- nav.html
|- folder1/
|- |- page.html
\- \- nav.html

page.html extends ../basic.html which includes nav.html

In that case, its the folder1/nav.html that gets included. If I remove folder1/nav.html, nothing gets included. How do I fix this? I could inline nav.html into basic.html, but there might be situations down the road where I want to have basic.html do some includes.

edit: The idea is that anything that inherited basic.html would get the toplevel nav.html template, but that doesn't seem to be the case, because the include nav.html directive is evaluated in the current directory of whatever template.

Upvotes: 2

Views: 1518

Answers (1)

Bernhard Vallant
Bernhard Vallant

Reputation: 50786

I do not know if I get everything correctly, but i think you have to enclose the include with a block?

basic.html:

...
{% block navigation %}
{% include "nav.html" %}
{% endblock %}

page.html:

{% extends "../basic.html" %}
{% block navigation %}
{% include "folder1/nav.html" %}
{% endblock %}

If you do not overwrite the navigation block in page.html the original include should be used...

Upvotes: 1

Related Questions