Support variable for page inheritance template
It will be great if we can use a variable as extended base value.
{% extends base_layout %}
{% block content %}
<h1>Title: {{ data.Title }}</h1>
<div>
{{ data.Content }}
</div>
{% endblock %}}
Also, I have check the code, the current inheritace model only support one level. Not sure how complex it will be to refactor the code to support variables and multiple inheritance.
Multiple inheritance is already supported. Variables in extends are not yet supported since the templates are compiled ahead of time.
@flosch yes, I saw that in the tagExtendsParser function. The tagExtendsNode should store the variable name and the template.execute method should resolve the path from the provided context.
I guess this is not easy to change.
It probably is, but it leads to JIT compiling of templates which is much more slower (like already supported for the include-tag). It's just not yet developed for the extends tag. I leave this ticket open as a feature request.
It has been some time. When I look for same feature I found this discussion.
My scenario is that a template(eg.userprofile.html) which shows custom content(eg. user profile) will be shown in different sites which have different layouts. So for me supporting the dynamic extend is important.
The only way I can think now is to use include only(giving up using extend) since include supports variable. base.html includes site1/layout.html which includes userprofile.html. Those include will be totally dynamic based on condition. Then the starting part will be from base - which almost didn't use benefit of extend at all.
Just to emphasis the importance of dynamic extend. Django has advantage of supporting this dynamic because of scripting language nature of python. Hope there is a middle way, eg. a predefined extending template list("site1/base.html, site2/base.html") and it can be supported only on top level(or maybe 2nd) so it's not complete dynamic to save performance.