I don't understand Jinja2 Call Blocks
I understand the concept, but I don't understand the syntax.
I'm going to use the example used on their site
{% macro render_dialog(title, class='dialog') -%}
<div class="{{ class }}">
<h2>{{ title }}</h2>
<div class="contents">
{{ caller() }}
</div>
</div>
{%- endmacro %}
{% call render_dialog('Hello World') %}
This is a simple dialog rendered by using a macro and
a call block.
{% endcall %}
What will be the output?
开发者_如何学Gosub-question (because I'm hella confused on how this works): Are you allowed to only have 1 caller per macro?
This is the output:
<div class="dialog">
<h2>Hello World</h2>
<div class="contents">
This is a simple dialog rendered by using a macro and
a call block.
</div>
</div>
So when we call render_dialog we pass 'Hello World' as title, when it reach caller()
it passes the contents of the call
block.
精彩评论