Can I import imports of another template in Jinja?

I would like to group my templates into categories and then just add 1 template instead of several. In simple words, when I import a template, I would like its import also to be imported.

Suppose I have a template a.jinja:

{% import 'b.jinja' as b %}
{% import 'c.jinja' as c %}

Both the template b.jinjaand c.jinjalook like a simple macro:

{% macro macroB() -%}
macroB
{%- endmacro %}

I also have a template test.jinjaimported above:

{% import 'a.jinja' as a %}
{{ a.b.macroB() }}   {# <- this does not work now #}

Is it possible to do this {{ a.b.macroB() }}?

+4
source share

Source: https://habr.com/ru/post/1659414/


All Articles