aboutsummaryrefslogtreecommitdiffstats
path: root/book
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--book/src/template_syntax.md22
1 files changed, 22 insertions, 0 deletions
diff --git a/book/src/template_syntax.md b/book/src/template_syntax.md
index ec35b94..4483562 100644
--- a/book/src/template_syntax.md
+++ b/book/src/template_syntax.md
@@ -10,6 +10,28 @@ context,
while `{{ user.name }}` will get the ``name`` field of the ``user``
field from the template context.
+## Using constants in templates
+
+You can use constants defined in your Rust code. For example if you
+have:
+
+```rust
+pub const MAX_NB_USERS: usize = 2;
+```
+
+defined in your crate root, you can then use it in your templates by
+using ``crate::MAX_NB_USERS``:
+
+```jinja
+<p>The user limit is {{ crate::MAX_NB_USERS }}.</p>
+{% set value = 4 %}
+{% if value > crate::MAX_NB_USERS %}
+ <p>{{ value }} is bigger than MAX_NB_USERS.</p>
+{% else %}
+ <p>{{ value }} is less than MAX_NB_USERS.</p>
+{% endif %}
+```
+
## Assignments
Inside code blocks, you can also declare variables or assign values