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?

Answers


I don't think this is possible. Just for your specific problem I guess it can be solves if you would place the site name before the block, and use the block just to append something to the site name.

Otherwise you could define SITE_NAME in your settings.py and have a context processor like

from django.conf import settings
def site_name(request):
    return {'SITE_NAME': settings.SITE_NAME}

so that you can use {{ SITE_NAME }} in your templates - this could make sense because the site name could be usefule at other places too...


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.


Need Your Help

User Click Tracking Library for Desktop App

c# desktop-application user-input tracking user-tracking

We are looking into the possibility of allowing users to opt into a program where they report what button clicks etc. they do, and I was wondering if anyone can suggest a good library which already...

Reading text into a buffer in c. (leaves out the last line of data when there is no newline on the textfile)

c file-io buffer line

I'm trying to read lines on a text file into a buffer by giving a function a line number as a parameter. This function then copies the text contained on that particular line of the file into the va...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.