macros

define & use macro in the same file

{% macro hello(name="john") %}
<mark>hello, {{name}}</mark>
{% endmacro %}

{{ hello() }}
{{ hello("doe") }}

define & use macros in different files (export and import)

{% macro hello(name) export %}
<mark>hello, {{name}}</mark>
{% endmacro %}

{% macro hi(name) export %}
<mark>hi, {{name}}</mark>
{% endmacro %}

Use it in another file:

{% import "macros.html" hello, hi as hi2 %}

{{ hello("john") }}
{{ hi2("doe") }}

macro calls another macro

Last updated