1

If template2.html contains {% extends 'template1.html' %} and template3.html contains {% extends 'template2.html' %}, what happens to things like {% block %}{% endblock %} and variables?

  • 2
    Thanks for sharing! Although, this isn't a "question", per se, and doesn't currently fit the format of this site. If you'd like to edit the question (so it's actually asking a question) and answer your own question, we'll be able to keep this thread open. – Lindsey D Jun 17 '15 at 22:48
  • I'm voting to close this question as off-topic because it is not a question. – Aaron Berkowitz Jun 18 '15 at 1:27
  • Since this has been fixed, I'm voting to "leave open". – Lindsey D Jun 18 '15 at 17:49
3

So I tried it, made three files, one extending the first, and another extending the second, and it all worked more or less as one would expect.

bozo.html

<!DOCTYPE HTML>
<html>
  <head>
    {% set title = title ~ 'Main' %}
    <title>{{ title }}</title>
  </head>
  <body>
    Where was {% block whereWasBozo %}Bozo?{% endblock whereWasBozo %}<br>
    Variable A is {{ a }}
  </body>
</html>

ex1_bozo.html

{% extends 'bozo.html' %}
{% set title = title ~ 'Bozo 1 = ' %}
{% set a = 'ex1' %}
{% block whereWasBozo %}
  Bozo wasn't here. 
{% endblock whereWasBozo %}

ex2_bozo.html

{% extends 'ex1_bozo.html' %}
{% set title = 'Bozo 2 + ' %}
{% set a = 'ex2' %}
{% block whereWasBozo %}
Bozo was in Bozoland.
{% endblock %}

When I pulled up page ex2_bozo.html, the end result was the page title said:

Bozo 2 + Bozo 1 = Main

and the web page said:

Where was Bozo was in Bozoland.
Variable A is ex1

So the blocks extend all the way through. The variables are first set in the file you initially call. They are modified in the middle 'extension' and modified again in the final extension.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.