Reference book of available twig-filters In templates are available most part of standart filters and some special filters. Full list of available filters you may see in the article. false W3sidGl0bGUiOiJBdXRvbWF0aW9uIiwidXJsIjoiL2RldmVsb3BlcnMvYXV0b21hdGlvbi8ifSx7InRpdGxlIjoiVHdpZy10ZW1wbGF0ZXMiLCJ1cmwiOiIvZGV2ZWxvcGVycy9hdXRvbWF0aW9uL3R3aWcvIn1d Automation /developers/automation/ ["developers","Automation"] ["developers","Automation","Twig-templates"] developers

Reference book of available twig-filters

In templates are available most part of standart filters and some special filters. Full list of available filters you may see in the article.

Filters can be applied to variable through vertical line. Examples of filter usage:

{{ name|striptags|title }}
{{ list|join(', ') }}

In templates are available most part of standart filters and some special filters. Full list of available filters you may see below.

NameDescription
absGetting the absolute value of number
avatar_urlReturns URL of user's photo (User type) or customer (Customer type)
If the photo is not specified or the object has different type, an empty string will be returned.
batchConversion of list to the two-dimensional list with equal elements quantity
capitalizeGetting string, first letter of which is converted to uppercase
dateConversion of date to string in the specified format
order.createdAt|date("Y-m-d") # Order creation date in format dd.mm.yyyy
"now"|date("Y-m-d H:i") # Current date in format dd.mm.yyyy hh:mm
date_modifyDate changing (for example, increasing on one day)
defaultReturns transmitted value in case, if the variable is not defined or empty
escapeDisplaying of symbols in the specified format
filterFilters elements of a sequence or mapping using an arrow function
firstGetting the first element in array
formatReplaces the symbols %s in string with transmitted values
joinGenerates the string from the array by combining array elements and adding a separator between them
json_encodeCreates JSON from the variable
is_subscribedReturns the customers's subscription flag (type Customer) to the specified channel (email, sms or waba).
{% if customer|is_subscribed('sms') %}
    You are subscribed to our SMS newsletters
{% endif %}
You can also check subscription to a specific category in the channel by passing the subscription category code as the second argument.
{% if customer|is_subscribed('email', 'news') %}
    You are subscribed to our news by Email
{% endif %}
keysReturns array keys
lastGetting the last element in array
lengthGetting the length of array or string
lowerConversion of all string symbols to lowercase
mergeMerging of array and another array
nl2brReplaces the line breaks with html-tag <br>
number_formatFormatting of number
rawGetting the value as is (without displaying)
replaceReplaces some substings with other
reverseInverts the values ordering in array or symbols in the string
roundRounds a number to a given precision
sliceThe array slice in specified frame
sortThe array sorting
splitSplits the string by substrings using transmitted separator
striptagsRemoving of html-tags
titleGetting the string, each word of which begins with the capital letter
trimRemoving of space symbols (or another) from the beginning and the end of string
truncateTruncates a string to the given length
upperChanges all string symbols to uppercase
url_encodeEncodes a given string as URL segment
ru_currencyConverts number to currency format
{{ 12345.12|ru_currency }} # RUB 12 345,12
{{ 5235.00|ru_currency('number') }} # 5 235
{{ 5235.00|ru_currency('number', false) }} # 5 235,00 - Displays the sum without removing zeros in kopeks
{{ 12345.12|ru_currency('words') }} # Twelve thousand three hundred forty-five rubles 12 kopeks
{{ order.totalSumm|ru_currency }} # Displays the order sum in currency format like RUB 12 345,12
{% set sum = order.totalSumm|ru_currency('parted') %} # Returns array of two elements. Element with the key 'integer' contains the whole part of the sum, element 'fractional' contains the fractional part
custom_fieldDisplays value of the specified order custom field or customer custom field
{{ order|custom_field('transaction_id') }} # Displays the value of order custom field with code "transaction_id"
{{ customer|custom_field('birthday') }} # Displays the value of customer custom field with code "birthday"
international_phoneConverts strings to telephone format with symbol + and international code in the beginning with removing of unnecessary symbols
{{ "8 (926) 123-45-67"|international_phone }} # displays +79261234567
{{ "(926) 123-45-67"|international_phone }} # displays +79261234567
{{ "7926123-45-67"|international_phone }} # displays +79261234567
{{ "044 123 45 67"|international_phone('UA') }} # displays +380441234567
{{ order.phone|international_phone }}
priceConverts number to currency format, substituting the currency symbol.
Filter parameters:
classes - the class, which will be added to the block with currency symbol
code - the currency code; if not specified, an attempt is made to determine the currency of the field to which the filter is applied, otherwise the default currency is used
stripZero - if false, there will be displayed zeros in kopeks
{{ order.totalSumm|price }} # 12 345 ₽
{{ order.totalSumm|price(stripZero=false) }} # 12 345,00 ₽
{{ order.totalSumm|price }} # $ 12 345
{{ order.totalSumm|price(stripZero=false) }} # $ 12 345,00
price_rangeConverts the range of numbers to currency format, substituting the currency symbol
numeric_declensionDisplays the word in the desired declension in accordance with the number (actual only for russian version)
{{ 1|numeric_declension("bag/s") }} # 1 bag
{{ 2|numeric_declension("bag/s") }} # 2 bags
{{ 15|numeric_declension("bag/s") }} # 15 bags
{{ 15|numeric_declension("bag/s", false) }} # bags
number_to_wordsDisplays the number by words
{{ 12345.12|number_to_words }} # Twelve thousand three hundred forty-five
buying_withReturns the recommended trading offers (Offer) of series "Also purchased". Allows to get up to 30 trading offers (6 by default).
# Gets and displays the names of 10 recommended offers for items in order
{% for item in order|buying_with(10) %}
  {{ item.name }}
{% endfor %}

# Gets and displays the names of 6 recommended offers for the first item in order
{% for item in order.orderProducts|first|buying_with %}
  {{ item.name }}
{% endfor %}
It is possible to transmit the name of recomendation service as the second parameter
If the parameter is not specified, default service can be used, which displays recommendations based on data of the system.
# Gets 3 recommended offers from RetailRocket service and displays their names
{% for item in order|buying_with(3, 'retailrocket') %}
  {{ item.name }}
{% endfor %}
analogsReturns trading offers (Offer) of series "Analogues". Allows to get up to 30 trading offers (6 by default).
# Gets and displays the names of 3 offers-analogues for items in order
{% for item in order|analogs(3) %}
  {{ item.name }}
{% endfor %} # Gets and displays the names of 6 offers-analogues for the first item in order {% for item in order.orderProducts|first|analogs %} {{ item.name }} {% endfor %}
It is possible to transmit the name of recomendation service as the second parameter
If the parameter is not specified, default service can be used, which displays recommendations based on data of the system.
# Gets 3 offers-analogues from RetailRocket service and displays their names
{% for item in order|analogs(3, 'retailrocket') %}
  {{ item.name }}
{% endfor %}
accompanyingDEPRECATED Use buying_with(3, 'retailrocket') instead
recommendationsReturns recommended SKUs (Offer) from the series specified by the first parameter. Allows to get up to 30 SKUs (6 by default).
# We get and display the name of 6 recommended SKUs from the "upsell" series for products in the order
{% for item in order|recommendations('upsell') %}
  {{ item.name }}
{% endfor %}

# We get and display the name of 6 recommended SKUs from the "analogs" series for the first product in the order
{% for item in order.orderProducts|first|recommendations('analogs') %}
  {{ item.name }}
{% endfor %}
The number of SKUs can be passed by the second parameter.
# We get 10 recommended SKUs from the "upsell" series and display their names
{% for item in order|recommendations('upsell', 10) %}
  {{ item.name }}
{% endfor %}
quantityFormats quantity according to system settings (integer/fractional)
offer_propertiesReturns array of trading offer properties
array(
  code => array(
    name  =>
    code  =>
    value =>
  )
)

{% for orderProduct in order.availableOrderProducts %}
  {% for property in orderProduct.offer|offer_properties %}
    {{ property.code }} - {{ property.name }} - {{ property.value }}
  {% endfor %}
{% endfor %}
containsIf the items array is transmitted by parameter, then function checks that the order contains at least one of them.
If the sections array is transmitted by parameter, then function checks that the order contains items of the specified sections.
{% set orderContainsProducts = order|contains(products) %}
lookedIf item(s) is transmitted as the parameter, the function checks that the customer has viewed any of the specified items.
If item section(s) is transmitted as the parameter, the function checks that the customer has viewed any items in the specified sections.
{% set isLookedProducts = customer|looked(products) %}
looked_products_countFunction returns the quantity of items viewed by customer
{% set lookedCount = customer|looked_products_count %}
countryReturns country name by ISO code (ISO 3166-1 alpha-2)
{{ 'RU'|country }} # Russia
{{ order.deliveryAddress.country|country }} # Country name from the order address
local_timeReturns local time by phone number, customer address or delivery address
{{ '+375 152 74-07-80'|local_time|date('H:i:s') }} # 15:53:23
{{ order.getDeliveryAddress|local_time|date('H:i:s') }}
{{ order.customer.getAddress|local_time|date('H:i:s') }}
{{ order.getPhone|local_time|date('H:i:s') }}
{{ order.getAnyPhone|local_time|date('H:i:s') }}
{{ order.customer.getAnyPhone|local_time|date('H:i:s') }}
file_urlReturns URL of attachment (type Attachment) or file (type File)
{% for attachment in order.attachments %}
  <a href="{{ attachment|file_url }}">{{ attachment.file.originalName }}</a>
{% endfor %}
qr_code_urlReturns the URL of the QR code of the specified size (in pixels) for a string
<img src="{{ '123'|qr_code_url }}">
<img src="{{ '123'|qr_code_url(200) }}">
If the argument is empty or isn't a string, then an empty string will be returned.
barcode_code128_urlReturns the URL of a barcode with the Code 128 type of the specified size (height in pixels) for a string
<img src="{{ '123'|barcode_code128_url }}">
<img src="{{ '123'|barcode_code128_url(100) }}">
If the argument is empty or isn't a string, then an empty string will be returned.
barcode_code39_urlReturns the URL of a barcode with the Code 39 type of the specified size (height in pixels) for a string
<img src="{{ '123'|barcode_code39_url }}">
<img src="{{ '123'|barcode_code39_url(100) }}">
If the argument is empty or isn't a string, then an empty string will be returned.
Thank you for your feedback.
Was this article helpful?
No
  • The recommendations did not help
  • There is no answer to my question
  • The text is difficult to understand
  • I do not like the described functionality
Yes
Previous article
Rules for working with Twig
Twig-templates are used for preparing of printed forms, letters, SMS templates and notifications. They look like HTML-layout with inclusions of twig-markup, so that it is needed basic knowledge of html and twig for creating templates.
Next article
Reference book of available twig-functions
Similarly with filters in templates are available most part of standart functions and some special functions. Full list of available functions you may see in the article.