I sometimes run into a situation where I want a template to be able to
extend from one of a set of possible base templates, which I achieve
by passing a "base_template" variable in the context to the {% extends
%} tag. Where this gets stuck, though, is if one of the possible
bases extends one of the other possible bases.
For example:
base_a.html:
first {% block content %}{% endblock %} last
base_b.html
{% extends "base_a.html" %}
{% block content %}left {% ??? %} right{% endblock %}
template.html
{% extends (either "base.a.html" or "base_b.html") %}
{% block content %}middle{% endblock %}
I'd like to be able to code template.html so that if it extends
base_a.html, the result is "first middle last", but if it extends
"base_b.html", the result is "first left middle right last".
I _think_ it would make sense to implement this with an improvement to
the semantics of the {% block %} tag, starting by allowing nested tags
with the same name.
If base_b.html were:
{% extends "base_a.html" %}
{% block content %}left {% block content %}{% endblock %} right{%
endblock %}
Then the {% block content %} in template.html could override the
_inner_ block in base_b.html. I think this behaviour is pretty
logical and consistent, unless I've missed something. I've hacked
around a bit with loader_tags.py but I'm finding it quite difficult to
get what I want with my limited understanding of how it works.
Do people think this idea makes sense? Is it worth taking the time to
write a patch for it?
--
You received this message because you are subscribed to the Google Groups
"Django developers" 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-developers?hl=en.