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. false W3sidGl0bGUiOiJBdXRvbWF0aW9uIiwidXJsIjoiL2RldmVsb3BlcnMvYXV0b21hdGlvbi8ifSx7InRpdGxlIjoiVHdpZy10ZW1wbGF0ZXMiLCJ1cmwiOiIvZGV2ZWxvcGVycy9hdXRvbWF0aW9uL3R3aWcvIn1d Automation /developers/automation/ ["developers","Automation"] ["developers","Automation","Twig-templates"] developers

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.

Example of function range usage:

{% for i in range(0, 3) %}
    {{ i }},
{% endfor %}

Similarly with filters in templates are available most part of standart functions and some special functions. Full list of available functions you may see below.

NameDescription
attributeFunction is used for an access to "dynamic" object properties
cycleFunction cycle passes in cycle the array of values
randomFunction allows to get the random value
rangeReturns the arithmetic progression of integers in the specified range
base_currency_codeDisplays the base currency code
price_symbolDisplays the symbol of the base currency
currency_patternDisplays the currency name by code
currency_numeric_codeDisplays the ISO 4217 numeric currency code
preview_image_tagGenerates tag <img/> for item image of the specified size
{{ preview_image_tag(op.offer.imageUrl, '100x100') }} # Preview of item image 100x100. It will be cutted if necessary.
{{ preview_image_tag(op.offer.imageUrl, '100x-', { alt: op.offer.displayName }) }} # Preview of image will have the width 100, and the height will be calculated proportionally.
minFinds the minimum value in the set or array of numbers
maxFinds the maximum value in the set or array of numbers
crm_settings_getAllows to get value of defined system setting
products_by_idsDEPRECATED Use entities_by_ids instead
new_productsReturns array of items with mark "New".
Accepts the parameters:
groups - groups, of which the items are selected
count - maximum quantity of selected items (20 by default)
properties - filter by item properties
# Gets items with mark "New" and size "XL"
{% set products = new_products(properties={size: 'XL'}) %}
best_selling_productsReturns array of the best selling items
Accepts the parameters:
groups - groups, of which the items are selected
count - maximum quantity of selected items (20 by default)
exclude - items excluded of selection
from - filter by date
to - filter by date
margin - minimum threshold of margin in absolute or relative values, items with lower margin will not be included in selection
properties - filter by item properties
customer - filter by customer
# Gets five the best selling items for the first quarter with margin higher than 10%
{% set products = best_selling_products(from='2016-01-01', to='2016-03-31', count=5, margin='10%') %}
most_visited_productsReturns array of the most viewed items
Accepts the parameters:
groups - groups, of which the items are selected
count - maximum quantity of selected items (20 by default)
exclude - items excluded of selection
from - filter by date
to - filter by date
margin - minimum threshold of margin in absolute or relative values, items with lower margin will not be included in selection
properties - filter by item properties
customer - filter by customer
# Gets five the most viewed items
{% set products = most_visited_products(count=5, exclude=[23, 34, 45]) %}
most_long_viewed_productsReturns array of the most long-viewed items
Accepts the parameters:
groups - groups, of which the items are selected
count - maximum quantity of selected items (20 by default)
exclude - items excluded of selection
from - filter by date
to - filter by date
margin - minimum threshold of margin in absolute or relative values, items with lower margin will not be included in selection
properties - filter by item properties
customer - filter by customer
# Gets five the most long-viewed items for January
{% set products = most_long_viewed_products(count=5, from='2016-01-01', to='2016-01-31') %}
product_groupsReturns the item groups array of the specified store up to a specified level of nesting (1 level by default). If the level value more than 3 is transmitted, then returns 3 levels. Array elements are sorted hierarchically
entity_by_codeReturns value of reference book by symbolic code
For selecting there are available object types: DeliveryType, DeliveryService, OrderMethod, OrderProductStatus, OrderType, PaymentStatus, PaymentType, Site, Status, StatusGroup, Store , LegalEntity
{{ entity_by_code('DeliveryType', 'delivery-type-10') }}
entity_by_idReturns content from the base by id
For selecting there are available object types: User, Site, Product, ProductGroup, Customer
When selecting the content Product it is possible to specify the identification field. Allowed values: id, externalId, article
{{ entity_by_id('User', 4) }}
entities_by_idsReturns array of contents from the base by ids
For selecting there are available object types: Product, ProductGroup
When selecting the content Product it is possible to specify the identification field. Allowed values: id, externalId, article
{% set products = entities_by_ids('Product', ['100', '101', '102'], 'externalId') %}
is_working_timeFunction checks whether the dateTime value is working time and returns result (true or false). As a dateTime the function can take DteTime object or string, whose format corresponds to php format of strtotime function. By default the current date and time is used.
is_working_time()
is_working_time('2015-01-01 10:00:00')
is_working_time(date('2015-01-01 10:00:00'))
is_working_time(order.getCreatedAt())
hashExecutes a one-way hashing of data with usage of specified hash-function (md5, sha1, sha256). The value returns as hex-tring lower case.
hash("md5", "test") # 098f6bcd4621d373cade4e832627b4f6
yandex_maps_apiGenerates a link to load API of Yandex.Maps
Accepts parameters:
version - Version
parameters - Array of additional parameters
{{ yandex_maps_api('2.0', { load: 'package.full', lang: 'en_US' }) }}
payment_linkReturns a link to pay an invoice of integration payment
To use the function, an integration payment type must be added in order
Accepts the parameters:
order - order with integration payment which use for creating payment invoice link
or
payment - integration payment which use for creating payment invoice link
# Gets a link to pay an invoice of first integration payment from order
{{ payment_link(order) }}
# Gets a link to pay an invoice of integration payment by the code of the type of integration payment
{% set integrationPayment = null %}
{% for payment in order.payments if integrationPayment is null %}
    {% if payment.type.code == 'yandex_kassa_shop1' %}
        {% set integrationPayment = payment %}
    {% endif %}
{% endfor %}

{% if integrationPayment is not null %}
    Your payment link: {{ payment_link(integrationPayment) }}
{% endif %}
userReturns the current user
user_statusReturns the status of the user (the object of the User type) passed as an argument to the function.
Returns the status of the current user when called without arguments.
{{ user_status(order.manager) }} # free
user_online_statusReturns the online status of the user (the object of the User type) passed as an argument to the function (true or false).
Returns the online status of the current user when called without arguments.
user_online_status(order.manager) # true
loyalty_account_infoReturns information about the bonus account of the participation in the Loyalty Program passed as an argument of the function
Returns an object of the LoyaltyAccountInfo type
loyalty_account_info(account).getWaitingActivationAmount()
loyalty_account_info(order.loyaltyAccount).getActiveAmount()
loyalty_account_info(customer.loyaltyAccountBySiteCode('test')).getBurnSoonAmount(10)
offer_inventoriesReturns an array of inventories (array of Inventory objects) of the offer by stores
Accepts parameters:
Offer offer - offer object
Site|null site = null - store object, optional (only inventories for the store's warehouses will be returned)
Store[]|Store|null store = null - warehouse object or array of warehouse objects, optional (only inventories for the specified warehouses will be returned)
# Various ways to call the function
{% set inventories = offer_inventories(op.offer) %}
{% set inventories = offer_inventories(op.offer, order.site) %}
{% set inventories = offer_inventories(op.offer, order.site, entity_by_code('Store', 'store-1')) %}
{% set inventories = offer_inventories(op.offer, null, [entity_by_code('Store', 'store-1'), entity_by_code('Store', 'store-2')]) %}
{% set inventories = offer_inventories(op.offer, null, order.shipmentStore) %}
# Get inventories for the order offer products for the 'store-1' warehouse with a check for the warehouse belonging to the order store
{% for op in order.availableOrderProducts %}
    {% set inventories = offer_inventories(op.offer, order.site, entity_by_code('Store', 'store-1')) %}
    {% for i in inventories %}
        {{ i.store.code }}:{{ i.quantity }}
    {% endfor %}
{% endfor %}
integration_module_http_callExecutes an HTTP request to the backend of the JS module and returns an object of type HttpCallResponse
Accepts parameters:
moduleCode - module instance code
path - path to which the request will be sent to the module's backend
payload - value of the optional POST-parameter payload in the form of a string or a json object
When calling the function, the system sends a POST request with Content-Type: application/x-www-form-urlencoded to the {baseUrl}/{path} backend of the module.
For example, if the module has set baseUrl equal to https://some-module.tech and specified path equal to /get-promocode, the request will be sent to https://some-module.tech/get-promocode .
The request may contain 2 form-encoded parameters:
clientId=<clientIdForAccount> - required parameter with the value clientId that the module has set in this system account
payload=<payload> - optional parameter if payload was passed
{% set response = integration_module_http_call('module-code', '/get-promocode', 'somePayload') %}
Your promo code is {{ response.status == 200 ? response.body : 'error' }}
# Sending a json object to payload
{% set response = integration_module_http_call('module-code', '/get-promocode', {order_id: 1}) %}
# If response.body is a json-encoded string of the form '{"promocode": "foobar"}', then access to the "promocode" field can be obtained through the "json" property
{{ response.body.json.promocode }}
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
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.
Next article
Canceling of the template rendering
There can be situation when it is necessary to cancel the template generating. The article describes how to do this.