How to extend a template that includes sub-templates?
Zola version: 0.8.0
I'd like to have a non-bloated base.html template so I made it this way.
{# base.html #}
<!DOCTYPE html>
<html>
{% include "head.html" %}
{% include "body.html" %}
</html>
{# body.html #}
<body>
{% block content %}{% endblock content %}
</body>
I though I could override the content bloc inside my about.html template that extends base.html but it appears to not be working, without any compilation issue though.
{# about.html #}
{% extends "base.html" %}
{% block content %}
Hello world in about.html
{% endblock content %}
My about.html page is rendered exactly as my base.html page so it appears that we cannot override an "included" block in inherited templates.
It is quite surprising but is that the intended behavior?
It is the intended behaviour, blocks are found when parsing the templates, include are not embedded in the AST, they are just their own nodes in it.
That's unlikely to be changed soon though
Hi @Keats I just encountered this issue myself. I have the same intention as the OP, to split page sections into 'partials' to keep the templates tidy, for example, my <head> section is 36 lines long with the various pieces of metadata.
The Tera docs suggest that the 'current context' is available to everything in the included template, and indeed this works with set or set_global, but blocks aren't working and logically I would expected them to in this case.
I see your original reply, but I'm wondering if there is another way to achieve this? What we essentially want is a way to tell the engine to treat it as if the contents of the partial were actually in-place where the include line is in the parent template.
Thanks for any help you can offer!