On 28 mar, 12:18, Vladimir Mihailenco <[email protected]>
wrote:
> Is there any way to override variable of parent (super) template in
> child template? For example, I have following templates:
>
> base.html
> <title>{{ title }}</title>
>
> {% block body %}
> <h1>{{ title }}</h1>
> {% block content %}{% endblock %}
> {% endblock %}
>
> child.html
> {% extends 'base.html' %}
>
> {% block content %}
> {% set title %}My title{% endset %}
> {% endblock %}

"title" is not even in your "content" block. But anyway: instead of
doing things backward, just define the blocks your need in your base
template, ie:

# base.html
<title>{% block page_title %}{{ title }}{% endblock %}</title>

{% block body %}
<h1>{% block body_title %}{{ title }}{% endblock %}</h1>
{% block content %}{% endblock %}
{% endblock %}


A block can be as "small" as you want - I often use them for
attributes like <body class="XXX"> etc.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to