From 94d3bc1dc039f26fb157e50215dcf139078ab231 Mon Sep 17 00:00:00 2001 From: Mo <76752051+mo8it@users.noreply.github.com> Date: Sun, 29 Oct 2023 16:28:53 +0100 Subject: Improve the macros section --- book/src/template_syntax.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'book') diff --git a/book/src/template_syntax.md b/book/src/template_syntax.md index 0b76b22..9716369 100644 --- a/book/src/template_syntax.md +++ b/book/src/template_syntax.md @@ -444,9 +444,9 @@ struct Item<'a> { ## Macros -You can define macros within your template by using `{% macro name(args) %}`, ending with `{% endmacro %}` +You can define macros within your template by using `{% macro name(args) %}`, ending with `{% endmacro %}`. -You can then call it later with `{% call name(args) %}` +You can then call it with `{% call name(args) %}`: ``` {% macro heading(arg) %} @@ -458,7 +458,7 @@ You can then call it later with `{% call name(args) %}` {% call heading(s) %} ``` -You can place templates in a separate file and use it in your templates by using `{% import %}` +You can place macros in a separate file and use them in your templates by using `{% import %}`: ``` {%- import "macro.html" as scope -%} @@ -466,8 +466,7 @@ You can place templates in a separate file and use it in your templates by using {% call scope::heading(s) %} ``` -It is also possible to use the name of the `macro` in `endmacro` in the -declaration: +You can optionally specify the name of the macro in `endmacro`: ```html {% macro heading(arg) %}
{{arg}}
{% endmacro heading %} -- cgit