Skip to content

Commit

Permalink
Add documentation for macro named arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Nov 20, 2023
1 parent fa5d5bb commit d9aab11
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions book/src/template_syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -587,3 +587,49 @@ You can optionally specify the name of the macro in `endmacro`:
```html
{% macro heading(arg) %}<p>{{arg}}</p>{% endmacro heading %}
```

You can also specify arguments by their name (as defined in the macro):

```
{% macro heading(arg, bold) %}
<h1>{{arg}} <b>{{bold}}</b></h1>
{% endmacro %}
{% call heading(bold="something", arg = "title") %}
```

You can mix named and non-named arguments when calling a macro:

```
{% call heading(bold="something", "title") %}
```

In this case, the named arguments will be passed to the related parameter and then the other
arguments will be placed in what remains. Let's explain it in code:

```
{% macro heading(arg1, arg2, arg3, arg4) %}
{% endmacro %}
{% call heading("something", arg2 = "title", arg4="ah", "b") %}
```

First it'll be replaced like this:

```
arg1 =
arg2 = "title"
arg3 =
arg4 = "ah"
```

Then `arg1` and `arg3` will be filled in the order of the arguments given to the macro call:

```
arg1 = "something"
arg2 = "title"
arg3 = "b"
arg4 = "ah"
```

0 comments on commit d9aab11

Please sign in to comment.