Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I don't understand Jinja2 Call Blocks

Tags:

python

jinja2

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?

sub-question (because I'm hella confused on how this works): Are you allowed to only have 1 caller per macro?

like image 865
Tri Noensie Avatar asked Feb 15 '11 06:02

Tri Noensie


1 Answers

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.

like image 107
Mariy Avatar answered Oct 03 '22 13:10

Mariy