Assignment
In templates, you can reassign variables. Inside loop bodies and macro control blocks, set assignments are only effective within the current block. Outside control blocks, they are globally effective. When you need to set a global variable inside 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 a global variable
{% 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] %}
Filters
Filters are used to modify output content. Filters are separated by a pipe (|). Filters that take arguments require parentheses. The input of the current filter is the output of the previous stage, and the final output is the output of the last filter.
Filters can be used with arithmetic operators and have the lowest priority.
{{ 1 + a | length }}
// Equivalent to the statement below
{{ (1 + a) | length }} // May produce errors in some contexts
// Recommended form
{{ a | length + 1 }}
Filters can also be applied to entire content blocks. Wrap content with {% filter name %} and {% endfilter %}, where name is the filter name.
{% filter upper %}
Hello
{% endfilter %}
The above outputs the all-uppercase string HELLO.
Filter blocks support template Inheritance block markers inside them.
{% filter upper %}
{% block content_to_be_upper_cased %}
This will be upper-cased
{% endblock content_to_be_upper_cased %}
{% endfilter %}
Assertion Tests
Used to test whether the input satisfies an assertion. The following example tests whether the input is an odd number.
{% if my_number is odd %}
Odd
{% endif %}
Negation is supported:
{% if my_number is not odd %}
Even
{% endif %}
Functions
Everkm Publish provides many built-in functions for common operations. Usage syntax:
{{ url_for(name="home") }}
Function arguments are wrapped in parentheses, with parameters in name=value form, separated by commas.
Functions can be used in the following contexts:
- Variable blocks:
{{ url_for(name="home") }} - Loop bodies:
{% for i in range(end=5) %}