Opened 5 years ago

Last modified 3 years ago

#12008 new Cleanup/optimization

included templates' blocks do not get processed as if they were from the context of the including page

Reported by: tim@… Owned by: nobody
Component: Documentation Version: master
Severity: Normal Keywords: include block
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Consider the following example:


{% block B %}{% include 'B.html' %}{% endblock %}


{% block test %}this is a test default from B{% endblock %}


{% extends 'A.html' %}
{% block test %}this is the test block from C{% endblock %}

This results in the "test" block being the default from the B template, as opposed to getting overriden with the test block that's defined in C.

However, the following works:


{% block test %}this is a test default from B{% endblock %}


{% extends 'A.html' %}
{% block test %}this is the test block from C{% endblock %}

In this case the test block from C is correctly used.

The documentation states:

If an included template contains any template code — such as tags or variables — then it will get evaluated with the context of the template that’s including it.

If this were true I believe the top example should be valid.

Attachments (0)

Change History (6)

comment:1 Changed 4 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

Marking this DDN because I'm not sure what the right interpretation is here. I can certainly see your point, but I can also see why the current behavior is happening. There is a design issue to consider here -- and in addition to determining whether you are correct, we need to determine if we can make this change without breaking backwards compatibility.

comment:2 Changed 4 years ago by russellm

#12064 is a related problem.

comment:3 Changed 4 years ago by russellm

  • Component changed from Template system to Documentation
  • Triage Stage changed from Design decision needed to Accepted

After discussing with ubernostrum on IRC, we've come to the decision that the current implementation is correct, and that the documentation should be updated to better explain the situation.

The formal explanation is that {% include %} doesn't participate in block structure - blocks are evaluated, then includes, then the remainder of template nodes.

comment:4 Changed 4 years ago by gvangool

#6646 discusses the same problem.

comment:5 Changed 3 years ago by julien

  • Easy pickings unset
  • Severity set to Normal
  • Type set to Cleanup/optimization

Calling this a doc cleanup/improvement as per Russ's comment.

comment:6 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

Add Comment

Modify Ticket

Change Properties
<Author field>
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.