Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit d9aab11

Browse files
Add documentation for macro named arguments
1 parent fa5d5bb commit d9aab11

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
@@ -587,3 +587,49 @@ You can optionally specify the name of the macro in `endmacro`:
587587
```html
588588
{% macro heading(arg) %}<p>{{arg}}</p>{% endmacro heading %}
589589
```
590+
591+
You can also specify arguments by their name (as defined in the macro):
592+
593+
```
594+
{% macro heading(arg, bold) %}
595+
596+
<h1>{{arg}} <b>{{bold}}</b></h1>
597+
598+
{% endmacro %}
599+
600+
{% call heading(bold="something", arg = "title") %}
601+
```
602+
603+
You can mix named and non-named arguments when calling a macro:
604+
605+
```
606+
{% call heading(bold="something", "title") %}
607+
```
608+
609+
In this case, the named arguments will be passed to the related parameter and then the other
610+
arguments will be placed in what remains. Let's explain it in code:
611+
612+
```
613+
{% macro heading(arg1, arg2, arg3, arg4) %}
614+
{% endmacro %}
615+
616+
{% call heading("something", arg2 = "title", arg4="ah", "b") %}
617+
```
618+
619+
First it'll be replaced like this:
620+
621+
```
622+
arg1 =
623+
arg2 = "title"
624+
arg3 =
625+
arg4 = "ah"
626+
```
627+
628+
Then `arg1` and `arg3` will be filled in the order of the arguments given to the macro call:
629+
630+
```
631+
arg1 = "something"
632+
arg2 = "title"
633+
arg3 = "b"
634+
arg4 = "ah"
635+
```

0 commit comments

Comments
 (0)