I tried and it does not work.
So far I wrote this:
{% extends 'base.html' %}
{% block title %}
{% setget title %}{% trans 'Pages' %}{% endset %}
{% endblock %}
{% block content %}
<h2>{{ title }}</h2>
{% endblock %}
and templatetag looks like this:
class SetNode(template.Node):
def __init__(self, key, nodelist, return_result=False):
self.key = key
self.nodelist = nodelist
self.return_result = return_result
def render(self, context):
value = self.nodelist.render(context)
for d in context.dicts:
d[self.key] = value
if self.return_result:
return value
else:
return ''
What do you think? The rationale behind this is that sometime I have
huge titles like this:
{% url foo as bar %}
{% block title %}{% blocktrans with a=b %}Title goes here {{ bar }}
{{ a }}{% endblocktrans %}{% endblock %}
and copy-pasting this from block to block is not funny... May be there
is another way to solve this?
On Mar 28, 6:34 pm, Bill Freeman <ke1g...@gmail.com> wrote:
> Try:
>
> {% extends 'base.html' %}
> {% with title="My title" %}
> {% block content %}
> Any other content stuff.
> {% endblock %}
> {% endwith %}
>
> No guarantees. Let us know if it works.
>
> Bill
>
> On Mon, Mar 28, 2011 at 6:18 AM, Vladimir Mihailenco
>
>
>
>
>
>
>
> <vladimir.web...@gmail.com> 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 %}
>
> > How to accomplish this using Django templates?
>
> > --
> > You received this message because you are subscribed to the Google Groups "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment