我有许多宏要在一个通用容器宏或模板中呈现。使用伪代码:
宏1
宏2
宏3
容器
在模板中:
"render macro1 inside of Container" e.g. {{ macro1 with Container }}
我不想每次都渲染 Container 然后再渲染里面的宏,我只需要指定,当这个宏与另一个宏一起包含时
我认为“调用”( http://jinja.pocoo.org/docs/templates/#macros ) 是我正在寻找的,但我现在不太明白。任何意见,如果不清楚我该如何澄清。
最佳答案
这对我有用:
{% 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 %}
关于python - Jinja2:说 'Render this macro inside another macro or template',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15796965/