Manipulating Data

Assignment

In templates, variables can be reassigned values. Within loop bodies and macro control blocks, set assignments are valid only for the current block, not within the control block, and are valid globally. When a global variable needs to be set within a control block, use the set_global statement.

{% set my_var = "hello" %}
{% set my_var = 1 + 4 %}
{% set my_var = some_var %}
{% set my_var = macros::some_macro() %}
{% set my_var = global_fn() %}
{% set my_var = [1, true, some_var | round] %}

Setting global variables

{% set_global my_var = "hello" %}
{% set_global my_var = 1 + 4 %}
{% set_global my_var = some_var %}
{% set_global my_var = macros::some_macro() %}
{% set_global my_var = global_fn() %}
{% set_global my_var = [1, true, some_var | round] %}

Filter

Filters are used to change the content of the output. Filters are separated by vertical lines (|), filters with parameters need to be enclosed in parentheses, the input of the current filter is the output of the previous paragraph, and the final output is the output of the last filter.

Filters can be used with arithmetic operators, which have the lowest priority.

{{ 1 + a | length }}
// is equivalent to the following statement
{{ (1 + a) | length }} // can be wrong in some semantics

// This is the recommended way to write it
{{ a | length + 1 }}

Filtering can be applied to an entire block of content. Use {% filter name %} and {% endfilter %} to wrap the content, with name being the name of the filter.

{% filter upper %}
    Hello
{% endfilter %}

The above outputs the string HELLO in all uppercase.

Filter blocks internally support the block tag of the template Inheritance.

{% filter upper %}
  {% block content_to_be_upper_cased %}
    This will be upper-cased
  {% endblock content_to_be_upper_cased %}
{% endfilter %}

Tests

Tests are used to check if an expression satisfies a condition. For example, the following example is used to test whether a number is odd or not.

{% if my_number is odd %}
 Odd
{% endif %}

Support for inverse operations

{% if my_number is not odd %}
 Even
{% endif %}

Functions

The Everkm provides a number of built-in functions for accomplishing common operations. They are used in the following forms:

{{ url_for(name="home") }}

Function arguments are wrapped in parentheses, parameter pairs are of the form name=value, and multiple parameter pairs are separated by commas.

The function is used in the following places

  • variable blocks: {{ url_for(name="home") }}
  • Loop bodies: {% for i in range(end=5) %}