Opened 7 years ago

Closed 2 years ago

Last modified 2 years ago

#12008 closed Cleanup/optimization (fixed)

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

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

Description

Consider the following example:

A.html:

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

B.html:

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

C.html:

{% 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:

A.html:

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

C.html:

{% 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.

Change History (12)

comment:1 Changed 7 years ago by Russell Keith-Magee

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedDesign 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 7 years ago by Russell Keith-Magee

#12064 is a related problem.

comment:3 Changed 7 years ago by Russell Keith-Magee

Component: Template systemDocumentation
Triage Stage: Design decision neededAccepted

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 6 years ago by Gert Van Gool

#6646 discusses the same problem.

comment:5 Changed 5 years ago by Julien Phalip

Easy pickings: unset
Severity: Normal
Type: Cleanup/optimization

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

comment:6 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:7 Changed 2 years ago by conor

Owner: changed from nobody to conor
Status: newassigned

I would like to try to fix this. I think the confusion has been mostly resolved in the newer documentation, as far as I can see here in the 'note'. I think it would be useful to add a version of russellm's clarification regarding blocks, as they are currently not mentioned. Would an example also be necessary?

comment:8 Changed 2 years ago by conor

Made pull request here.

comment:9 Changed 2 years ago by conor

Has patch: set

comment:10 Changed 2 years ago by conor

Made updated pull request with the wording suggested by evildmp, which I agree does a better job of explaining the process.

comment:11 Changed 2 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 80b8d3bee035b56b0d9ac57dd732dffa3b2d5f3c:

Fixed #12008 -- Clarified relationship between template blocks and includes.

Thanks Daniele Procida for suggested wording.

comment:12 Changed 2 years ago by Tim Graham <timograham@…>

In b729ef0bda5009389da7e3a5498dc1f6233761d6:

[1.7.x] Fixed #12008 -- Clarified relationship between template blocks and includes.

Thanks Daniele Procida for suggested wording.

Backport of 80b8d3bee0 from master

Note: See TracTickets for help on using tickets.
Back to Top