3

I have base template that contains macro like this

{%- macro local_vars(d) -%}
{%- block local_vars %}
{% endblock -%}
{%- endmacro -%}

So I would like to override this block in the child template and still use the variable "d" from the base template. I tried this:

{%- block local_vars -%}
{{d.out.type}} {{d.component_name}}_out;
{%- endblock -%}

, but I get error:

UndefinedError: 'd' is undefined.

I also tried to create the new variable inside the block in the base template, and access it with {{super}}:

base:
{%- macro local_vars(d) -%}
{%- block local_vars %}
    {% set dict = d%}
{% endblock -%}
{%- endmacro -%}

child:
{%- block local_vars -%}
{{super}}
{{dict.out.type}} {{dict.component_name}}_out;
}
{%- endblock -%}

, but this doesn't work either. I only get the new error:

UndefinedError: 'function object' has no attribute 'out'

I haven't used blocks before, so any help would be highly appreciated. If there is a way to pass the variable to the block in child template, that would be the most painless solution for me, but I'm opened for suggestions.

Thanks in advance.

Alen
  • 55
  • 6
  • 1
    Does scoping the block help? [jinja docs](http://jinja.pocoo.org/docs/dev/templates/#block-nesting-and-scope) – qwattash May 13 '15 at 15:42
  • @qwattash Yes it does, thank you! Weird thing is that I already tried that before I asked this question, but for some reason it didn't work. I probably just forgot to save the file before running generation. – Alen May 14 '15 at 08:33

0 Answers0