Skip to main content
Version: 1.0.0

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.

HelperTypeDescription
trpFilter, functionTranslates a string and replaces placeholders
isArrayFilter, functionTests whether a value is an array
uniqueFilter, functionRemoves duplicated values from an array
formatDateFilter, functionFormats the given date or time
formatPriceFilter, functionFormats the given price
implodeAttributeFilterJoins attribute labels with the given delimiter
buildQueryParamsFilterBuilds a query string from a URL and parameters
createSlugFilterCreates a slug from a string
base64_encodeFilterEncodes a string as Base64
isMinifyEnabledFunctionChecks 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'}) %}
warning

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.

warning

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 %}