2013-04-03 72 views
2

我想在一個公共容器宏或模板中渲染多個宏。隨着僞代碼:Jinja2:說'將此宏渲染到另一個宏或模板內'

宏1

Macro2

Macro3

集裝箱

在模板中:

"render macro1 inside of Container" e.g. {{ macro1 with Container }} 

我不想去通過渲染集裝箱然後每次它裏面的宏,我只需要指定,什麼時候這個宏,附上這個其他的宏

我認爲'呼叫'(http://jinja.pocoo.org/docs/templates/#macros)是我正在尋找,但我現在不太明白。任何輸入,以及如果我不明白這一點,我可以澄清這一點。

回答

2

這個工作對我來說:

{% 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 %}