Variables
Blutui passes variables to the templates for manipulation in the template. Variables may have attributes or elements you can access, too.
Use a dot (.
) to access attributes of a variable:
{{ foo.bar }}
If a variable or attribute does not exist, you will receive a null
value.
If you want to access a dynamic attribute of a variable, use the attribute function instead. The attribute
function is also useful when the attribute contains special characters (like -
that would be interpreted as the minus operator):
{# equivalent to the non-working foo.data-foo #}
{{ attribute(foo, 'data-foo') }}
Global Variables
The following variables are always available in templates:
_self
: references the current template name;_context
: references the current context;_charset
: references the current charset.
Setting Variables
You can assign values to variables inside code blocks. Assignments use the set tag:
{% set foo = 'foo' %}
{% set foo = [1, 2] %}
{% set foo = {'foo': 'bar'} %}