Functions and block statements
sagotch opened this issue · 1 comments
sagotch commented
With these two files:
<html><head></head><body>{% block body %}{% endblock %}</body></html>
{%- function foo () -%}{{ "HELLO" }}{%- endfunction -%}
This wont work
{%- extends "template.jingoo" -%}
{%- include 'utils.jingoo' -%}
{%- block body -%}{{ foo () }}{%- enblock -%}
This will
{%- extends "template.jingoo" -%}
{%- block body -%}{%- include 'utils.jingoo' -%}{{ foo () }}{%- enblock -%}
Because functions are treated as variables and not hoisted as macro are, we can easily run into this kind of errors.
Should not functions be treated as macros?
tategakibunko commented
To avoid this error, I always include
util like templates before extends
.
{%- include 'utils.jingoo' -%}
{%- extends "template.jingoo" -%}
{%- block body -%}{{ foo () }}{%- enblock -%}
and it works well.