Module ructe::Template_syntax
source · Expand description
This module describes the template syntax used by ructe.
The syntax is inspired by Twirl, the Scala-based template engine in Play framework, but of course with rust types expressions instead of scala.
A template consists of three basic parts:
First a preamble of use
statements, each prepended by an @ sign.
Secondly a declaration of the parameters the template takes.
And third, the template body.
@use any::rust::Type;
@(name: &str, items: &[Type])
<html>
...
</html>
The curly brackets, {
and }
, is used for blocks (see Loops,
Conditionals, and Calling other templates below).
To use them in the template body, they must be escaped as @{
and
@}
.
Modules
A value expression can be as simple as
@name
to get the value of
a parameter, but more complicated expressions, including function
calls, are also allowed.A ructe
@for
loop works just as a rust for
loop,
iterating over anything that implements std::iter::IntoIterator
,
such as a Vec
or a slice.Both
@if
statements with boolean expressions and match-like
guard @if let
statements are supported.The ability to call other templates for from a template makes
both “tag libraries” and “base templates” possible with the
same syntax.