Functions and filters
This page documents custom Simplia functions. For standard Twig functions and filters, see the official Twig documentation. For an overview of custom Simplia filters, see the Simplia filters section.
Every custom function is listed below (eshop/inc/Twig_Extension_Filtry.php; tests-js/tpl/functions-doc.test.mjs fails when one is missing here). Before you decide that a template cannot know something — the visitor's country, the next working day, whether a customer subscribed to the newsletter — look here and in Objects.
Visitor and language versions
| Function | Returns |
|---|---|
ip_stat(ip?) | The visitor's country as an ISO code ("CZ", "SK", "DE"), or false. Without an argument the current visitor's IP. |
geoip(ip?) | {continent_code, country_code, country_name, city, postal_code, latitude, longitude} for the visitor, or false. |
recommendedAlternativeShop() | The shop's domain in the visitor's country/language when it is not the current one, else null: a LanguageUrl with url, hreflang, shortDomain and shop (shop.country.code). For "you seem to be from Slovakia, switch?" dialogs. |
availableExternalLoginServices() | The social logins the shop has configured: a list of "facebook", "seznam" (Czech only), "google", "discord". |
newsletter_subscribed(email) | Whether the address (or the visitor's newsletter cookie) has a valid newsletter consent. |
lang(key) | The legacy system translation of key in the context's language (lang("Telefon")); for your own texts use {% trans %}. |
{% if recommendedAlternativeShop() is not empty and this.cookie('cookie_dialog_country') != 'neukazovat' %}
<a href="{{ recommendedAlternativeShop().url }}" if:hreflang="recommendedAlternativeShop().hreflang ? recommendedAlternativeShop().hreflang">
{{ recommendedAlternativeShop().shortDomain }}
</a>
{% endif %}
{% if ip_stat() == 'SK' %} … {% endif %}Dates
| Function | Returns |
|---|---|
isPracovniDen(date?, days = [1,2,3,4,5]) | Whether the date (default today; 'now', '+1 day', a date) is a working day: one of days (1 = Monday … 6 = Saturday, 0 = Sunday) and not a public holiday. |
pristiPracovniDen(date?) | The next working date after date. |
Filter addWorkingDays(n) adds working days to a date ('now'|addWorkingDays(2)).
Links, images, maps
| Function | Returns |
|---|---|
iUrl(presenter, params?, platform?) | An internal shop URL: see Internal links. |
path(route, params?) | The path of a named route (path('frontend.…')). |
images(file, tag?) | The URL of a file in the layout's images/ (versioned; per-language files of a master). |
QR(url, size = 250) | A QR code of url as an SVG data URI (<img src="{{ QR(product.url) }}">). |
mapyczLink(search) | A mapy.cz link for an address or place. |
mapyczApiKey() | The shop's mapy.cz API key, for an embedded map. |
addressToGps(address) | [latitude, longitude] of an address (geocoded, cached a day), or null. |
ajaxMenuUrl(code) | The URL a lazily loaded menu fetches its HTML from (/_menu/<code>/<image format of this page>). |
getPage(url, timeout = 5), getPageCache(url, ttl, timeout = 5) | The body of a page on this shop (/…) or an allow-listed host; the second caches it for ttl seconds. |
Lists and entities
| Function | Returns |
|---|---|
uniqueEntities(lists, limit?) | Several lists merged without duplicates, up to limit (below). |
isInList(entity, list) | Whether the entity (product, category, …) is in the list by id: isInList(cat, this.templateAttributes.menu_hide_categories). |
categoryTree(…) | The category tree for menus (legacy; prefer repository.category). |
calculateImageSize(img, width, height) | [width, height] of the image resized to fit the box, keeping its ratio. |
productEntity(product) | Deprecated: a legacy product as a template object. |
tagContent('headline') | The current category's name on a category listing. |
rand(min, max), array_combine(keys, values) | As in PHP. |
Ready-made HTML
They render the platform's markup; style it, do not rebuild it.
| Function | Renders |
|---|---|
gdprForm(options) | The GDPR consent checkboxes of a form (see Components). |
externalLoginButton(service, options?), facebookLoginForm(options?), externalLoginTerms() | Social login buttons and their terms. |
videoTag(video, width, height, attributes?, controls?, loop?, autoplay?, color?) | A video player for a Video. |
imgTag(img, sizes, formats, options, attributes) | A responsive <img>/<picture> (what i:img uses). |
bannersHtml(banners, settings?), img360Html(product, settings?, labels?) | Banner slides, a 360° product view (what i:banners and the 360 component use). |
branchSelectHtml(…), filter_widget(attribute, options?) | The pickup-point picker of the cart, a filter widget. |
inline_js(file, once?) | A script from the layout inlined into the page. |
Internal
Used by the platform's components and attributes; do not call them yourself: encrypt_listing, encrypt_dynamic_attribute, encrypt_dynamic_attribute_context, replace_menu_class_placeholders, active_menu_placeholder_class, href_action_type, entity_href, filterListSerialized, vite_entry_script_tags, vite_entry_link_tags.
Test is phone: a valid phone number ({% if customer.phone is phone %}).
uniqueEntities
Processes an array of entities, removes duplicates, and optionally limits the result to a given count. A typical use case is displaying five products that are similar, in the same category, or on sale (depending on what is available).
If a maximum count is defined, items are iterated only until the count is met. If two product listings are defined as sources and the count is already satisfied by the first, the second is never loaded from the database.
{% for image in uniqueEntities([product.image, product.currentImages, product.imagesWithoutEnumValue], 5) %}
{{ image.alt }}
{% endfor %}