Jinja2:说出“将此宏渲染到另一个宏或模板中”

blu*_*ank 4 python macros templates jinja2

我想在一个普通的容器宏或模板中渲染多个宏。使用伪代码:

宏1

宏2

宏3

容器

在模板中:

"render macro1 inside of Container" e.g. {{ macro1 with Container }}
Run Code Online (Sandbox Code Playgroud)

我不想每次都渲染容器,然后再渲染其中的宏,我只需要指定何时将此宏与另一个宏一起括起来

我认为'call'(http://jinja.pocoo.org/docs/templates/#macros)是我想要的,但我现在还不太了解。任何输入,如果不清楚,我将如何澄清。

blu*_*ank 5

这对我有用:

{% macro _enclosure() %}
    <div id="topenclosure">hello I'm on top</div>
        {{ caller() }}
    <div id="bottomenclosure">hello I'm on the bottom</div>
{% endmacro %}

{% macro account_user_profile_macro(i) %}
    {% call _enclosure() %}
        {{i.__dict__}}
    {% endcall %} 
{% endmacro %}
Run Code Online (Sandbox Code Playgroud)