Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append to site <title> in Django template using block.super

I have 3 Django templates:

base.html

<title>{% block title %} SITE NAME {% endblock %}</title>

default.html

{% extends "base.html" %}
{% block title %} {{ block.super }} - SECTION NAME {% endblock %}

main.html

{% extends "default.html" %}
{% block title %} {{ block.super }} {% endblock %}

I'd like to get SITE NAME in template main.html i.e. the content of the parent of the parent block. Something like

{{ block.super.super }}

Is this possible?

like image 386
San4ez Avatar asked Dec 01 '10 10:12

San4ez


1 Answers

Note, Django 1.2.3 seems to already do what you want. Assuming SITE_NAME is exposed via a context_preprocessor like lzerscience illustrates, block.super should expose it through all the layers of inheritance.

main.html

{% extends "default.html" %}
{% block title %} {{ block.super }} - MAIN{% endblock %}

That displays the title "SITE NAME - SECTION NAME - MAIN" for me.

like image 133
Cerin Avatar answered Oct 16 '22 19:10

Cerin