Crinja Templates
Azu uses Crinja a powerful template engine built for the Crystal Language
,Templates::Renderable will define a private function named render(template : String, data)
with one clause per file system template.
Template Syntax
The following is a quick overview of the template language to get you started.
More details can be found in the template guide. The original Jinja2 template reference can also be helpful, Crinja templates are mostly similar.
Expressions
In a template, expressions inside double curly braces ({{
... }}
) will be evaluated and printed to the template output.
Assuming there is a variable name
with value "World"
, the following template renders Hello, World!
.
The properties of an object can be accessed by a dot (.
) or square brackets ([]
). Filters modify the value of an expression.
Tests are similar to filters but are used in the context of a boolean expression, for example as a condition of an if
tag.
Tags
Tags control the logic of the template. They are enclosed in {%
and %}
.
The for
tag allows looping over a collection.
Other templates can be included using the include
tag:
Macros
Macros are similar to functions in other programming languages.
Template Inheritance
Template inheritance enables the use of block
tags in parent templates that can be overwritten by child templates. This is useful for implementing layouts:
Last updated