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:

{{ }}
It’s important to know that the curly braces are not part of the variable but the print statement. When accessing variables inside tags, don’t put the braces around them.

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 #}
{{ 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'} %}