Filters
The following filters and Twig functions are available to templates.
Some helpers are registered in both forms, so you can use whichever reads better in the template.
Examples below use filter syntax for brevity. Helpers marked Filter, function can also be called as Twig functions.
| Helper | Type | Description |
|---|---|---|
| trp | Filter, function | Translates a string and replaces placeholders |
| isArray | Filter, function | Tests whether a value is an array |
| unique | Filter, function | Removes duplicated values from an array |
| formatDate | Filter, function | Formats the given date or time |
| formatPrice | Filter, function | Formats the given price |
| implodeAttribute | Filter | Joins attribute labels with the given delimiter |
| buildQueryParams | Filter | Builds a query string from a URL and parameters |
| createSlug | Filter | Creates a slug from a string |
| base64_encode | Filter | Encodes a string as Base64 |
| isMinifyEnabled | Function | Checks whether minification is enabled |
trp
Translates a given string by using Craft::t() and replaces placeholders with given parameters.
{% set label = 'Your order number is: %order_number'|trp({'order_number': '#123456'}) %}
This filter is deprecated. To replace variables in a string, just use the in-built function, ex.:
{% set label = 'Your order number is: {order_number}'|t('yui', {'order_number': '#123456'}) %}
isArray
Tests whether a value is an array.
{% if someVariable|isArray %}
{# Your code here #}
{% endif %}
unique
Removes duplicated values from an array.
{% set uniqueArray = mixedArray|unique %}
formatDate
Formats the given date or time string using the specified format. Default value is Y-m-d H:i:s.
{% set formattedDate = orderedAt|formatDate('d.m.Y') %}
formatPrice
Formats the given price with the specified currency. Default value is Eur.
{% set finalPrice = amount|formatPrice('HUF') %}
implodeAttribute
Joins attribute labels with the given delimiter.
This filter was deprecated. The Product Elements now use in-built CraftCms fields for attributes.
buildQueryParams
Builds a query string with the given URL and parameters.
{% set fullUrl = absoluteUrl|buildQueryParams(craft.app.request.queryParams) %}
createSlug
Creates a slug from the provided string using the plugin helper.
{% set slug = 'My Product Title'|createSlug %}
{% set slugWithCaps = 'My Product Title'|createSlug(true) %}
base64_encode
Encodes the given string as Base64.
{% set encodedValue = 'yui'|base64_encode %}
isMinifyEnabled
Checks whether the minify plugin is available.
{% if isMinifyEnabled() %}
{# Do something #}
{% endif %}