Skip to content

Commit ced67ce

Browse files
committed
add docs
Signed-off-by: Michael Pollind <[email protected]>
1 parent b468ee3 commit ced67ce

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

book/src/template_syntax.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,52 @@ Then if you don't pass a value for this argument, its default value will be used
919919
{% call heading(1, 2) %}
920920
```
921921

922+
### Call
923+
924+
you can specify a block for a call to be passed down as used as apart of a macro. For this case
925+
a block is denoted by `{% call(args) macro() %}`, ending with `{% endcall %}`. for an call with no args it's
926+
denoted by `{% call() macro() %}`, ending with `{% endcall %}`. Inside a macro, the `caller()` macro
927+
is called to pull in the block from the caller.
928+
929+
```jinja
930+
{% macro render_dialog(title, class='dialog') -%}
931+
<div class="{{ class }}">
932+
<h2>{{ title }}</h2>
933+
<div class="contents">
934+
{% call caller() %}
935+
</div>
936+
</div>
937+
{%- endmacro %}
938+
939+
{% call() render_dialog('Hello World') %}
940+
This is a simple dialog rendered by using a macro and
941+
a call block.
942+
{% endcall %}
943+
944+
```
945+
946+
here is an example with a call block using arguments:
947+
948+
```jinja
949+
{% macro dump_users(users) -%}
950+
<ul>
951+
{%- for user in users %}
952+
<li><p>{{ user.username }}</p>{% call caller(user) %}</li>
953+
{%- endfor %}
954+
</ul>
955+
{%- endmacro %}
956+
957+
{% call(user) dump_users(list_of_user) %}
958+
<dl>
959+
<dt>Realname</dt>
960+
<dd>{{ user.realname }}</dd>
961+
<dt>Description</dt>
962+
<dd>{{ user.description }}</dd>
963+
</dl>
964+
{% endcall %}
965+
966+
```
967+
922968
## Calling Rust macros
923969

924970
It is possible to call rust macros directly in your templates:

0 commit comments

Comments
 (0)