Open natevw opened 10 years ago
Thanks for pointing this! I'll examine the problem later this month.
Thanks! I did notice this bit in the Custom template tags docs:
Variable scope in context Any variable set in the context will only be available in the same block of the template in which it was assigned. This behavior is intentional; it provides a scope for variables so that they don’t conflict with context in other blocks.
I spent some time in the source debugging this and some related issues, but I really haven't fully grokked the implications, or why "sameas" is currently working across blocks in certain circumstances.
I think I've got a better understanding of this now:
{% load sameastags %}
was done in a particular file, it won't capture rendered blocks at allSo given all that, to share nested blocks between parent blocks you have to do something like this:
{% load sameastags %}
{% block parent %}
<!-- {% block reused_block %}{% endblock %} {# have to render here in parent #} -->
{% block container_one %}{% endblock %}
{% block container_two %}{% endblock %}
{% endblock %}
{% load sameastags %}
{% block container_one %}One reuses: {% sameas reused_block %}{% endblock %}
{% block container_two %}Two reuses: {% sameas reused_block %}{% endblock %}
The container has to both load the sameas library and to render the reused block to set the cached contents "low enough" down in the rendering context stack. If container_one tried to render the block itself, it would be stored but only until that block "closed", then it would be missing for container_two.
You might be able to fix this by "manually" storing the rendered contents farther down in the block stack — but be careful since the lowest level might be shared between threads/page renders (I could be mistaken?).
t_base_base.html:
t_base.html:
t_page.html
If you leave the sameastags commented out in t_base_base.html, even though it doesn't directly use the
sameas
tag, you get:There seems to be a bit more at play here with context pushing/popping, but I suspect the main trouble stems from the lack of this plugin's BlockNode override when rendering the parent templates.