pebble icon indicating copy to clipboard operation
pebble copied to clipboard

Extended templates cannot overwrite inherited blocks if they are added via inlcude

Open 2pt3 opened this issue 10 years ago • 2 comments

Consider three templates: Base.html <h1>Base</h1> {% block sectionA %}[base sectionA]{% endblock %} {% include 'Included' %}

Included.html <h2>Included</h2> {% block sectionB %}[included sectionB]{% endblock %}

Extended.html {% extends 'Base' %} {% block sectionA %}({{ parent() }})=>[extended sectionA]{% endblock %} {% block sectionB %}({{ parent() }})=>[extended sectionB]{% endblock %}

If Extended.html is used for output, it generates the following:

Base ([base sectionA])=>[extended sectionA] Included [included sectionB]

I would assume both blocks should be replaced with extended blocks, but the block defined in the included template is not being replaced.

2pt3 avatar Apr 13 '16 10:04 2pt3

It looks like Twig uses a separate keyword to accomplish this, http://twig.sensiolabs.org/doc/tags/use.html, and they have very strict criteria that must be met by the template being included.

It's seems like a nice feature that probably requires more thought, discussion, and work than I'm able to put in at this time. I'm willing to review a pull request but I suspect that because Twig used a separate keyword, whoever implements this will find that this is more complicated than it first appears.

mbosecke avatar Sep 22 '16 03:09 mbosecke

Isn't it possible to process the include first and rather than parsing, just pasting it's content into the template intermediately and finally evaluate the resulting template? I am not aware of the implementation, thus I suspect it is as you said - more complicated than it first appears.

RoboticRaven avatar Apr 26 '19 19:04 RoboticRaven