Doka avatar

Журнал Эмбеддед-Инженера

О микроэлектронике, радиотехнике и хобби

Dmitry Murzinov

2 минут чтения

Содержание

Циклы

  • loop.index - The current iteration of the loop. (1 indexed)

  • loop.index0 - The current iteration of the loop. (0 indexed)

  • loop.revindex - The number of iterations from the end of the loop (1 indexed)

  • loop.revindex0 - The number of iterations from the end of the loop (0 indexed)

  • loop.first - True if first iteration.

  • loop.last - True if last iteration.

  • loop.length - The number of items in the sequence.

  • loop.cycle - A helper function to cycle between a list of sequences.

  • loop.depth - Indicates how deep in a recursive loop the rendering currently is. Starts at level 1

  • loop.depth0 - Indicates how deep in a recursive loop the rendering currently is. Starts at level 0

  • loop.previtem - The item from the previous iteration of the loop. Undefined during the first iteration.

  • loop.nextitem - The item from the following iteration of the loop. Undefined during the last iteration.

{{ customer.email.split('@') | last }}

{% set age = time | from_timestamp('%Y') -  customer.date_of_birth.split('-')[0] %}

{{ (time + 604800) | from_timestamp('%d-%m-%y')}}

Форматирование

{{ "%0.2f" | format(item.price | float) }}

"email_id": {{ customer.email | lower | json }}

Phone number without symbols, spaces or leading zeros

{{ customer.phone | replace(' ','') | replace('+','') | replace('(','')| replace(')','') | replace('-','') | int }}

Несортированное

Convert string from JSON

item.str | from_json

Hashing a string

To get the sha1 hash of a string:
{{ 'test1'|hash('sha1') }}

To get the md5 hash of a string:
{{ 'test1'|hash('md5') }}

Time/Date

{% set timestamp = time %}

Output time in the correct timezone

{% set timezone = 'Europe/Bratislava' %}
{% set offset = (time - time | from_timestamp('%x %X %f') | to_timestamp('%x %X %f', timezone=timezone)) | round %}
{% set calculated_time = time + offset %}
{{ calculated_time | from_timestamp('%x %X') }}
    • None

Последние записи

Разделы