Please note I am behind on zola versions, mine is 0.18.0
Reproduction:
zola init
- create content/_index.md
- create templates/base.html
<!doctype html>
<html>
<body>
{% block body %}{% endblock %}
</body>
</html>
- create failing templates/index.html
{% extends "base.html" %}
{% if section %}
{% set this = section %}
{% else %}
{% set this = page %}
{% endif %}
{% block body %}
{{ this.content | safe }}
{% endblock %}
zola serve
fails:
Error: Failed to build the site
Error: Failed to render section '/home/andrew/projects/tera-bug-poc/content/_index.md'
Error: Reason: Failed to render 'index.html'
Error: Reason: Variable `this.content` not found in context while rendering 'index.html'
- Place if…else inside any block (this example only has a body)
zola serve
succeeds
I think I am just not understanding something about how Tera works here and was hoping someone could explain why “7” works. I thought variable scope might be limited to blocks, but when I have multiple blocks, I found that I could place the assignment in multiple positions and it would work, for instance, place the variable assignment in “meta” block but successfully access the variable in “body” block.