Update book/src/template_syntax.md

Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
This commit is contained in:
René Kijewski 2024-08-13 17:45:03 +02:00 committed by GitHub
parent 1a74d9350e
commit 6e75cb0802
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -594,10 +594,7 @@ and the same restrictions as in Rust, e.g. that it can be used only once in a sl
```
The `{% else %}` node is syntactical sugar for `{% when _ %}`.
If used, it must come last, after all other `{% when %}` blocks.
A `{% match %}` must be exhaustive, i.e. all possible inputs must have a case.
This is most easily done by using proving an `{% else %}` case,
if not all possible values need an individual handling.
If used, it must come last, after all other `{% when %}` blocks:
```jinja
{% match answer %}
@ -606,6 +603,10 @@ if not all possible values need an individual handling.
{% endmatch %}
```
A `{% match %}` must be exhaustive, i.e. all possible inputs must have a case.
This is most easily done by using proving an `{% else %}` case,
if not all possible values need an individual handling.
Because a `{% match %}` block could not generate valid code otherwise,
you have to provide at least one `{% when %}` case and/or an `{% else %}` case.