Skip to content
shopdepot.dev

Reference

Filters

Every filter a theme can use: ShopDepot filters for prices, images, assets and translations, plus the allowed Twig filters.

View as Markdown

Generated from the platform code - always matches what the theme engine allows.

Filters change a value: {{ product.price|money }}. Arguments go in parentheses, by position or by name - {{ image|image_url(width: 800) }}. A filter that is not listed here does not exist in a theme: the template fails to save.

ShopDepot

money

Formats an amount in minor units (grosze, cents) as a price in the store language - 12900 becomes 129,00 zł. Every price on an object is in minor units.

{{ amount|money(currency = shop.currency) }}

Example:

{{ product.price|money }}

money_with_currency

Like money, with the ISO currency code appended - for stores that sell in several currencies.

{{ amount|money_with_currency(currency = shop.currency) }}

Example:

{{ cart.totalPrice|money_with_currency }}

image_url

Address of an image at a width. Accepts a media object, a file from a setting or a plain address. The platform keeps WebP renditions from 320 to 2400 pixels wide and returns the smallest that covers the width; the heavy original is never sent to visitors.

{{ image|image_url(width = 800) }}

Example:

{{ product.featuredMedia|image_url(width: 1600) }}

image_tag

An <img> tag with decoding="async". Images are lazy by default; give the first visible image loading: 'eager' so it does not wait, and the main image above the fold (the LCP image) fetchpriority: 'high' so the browser fetches it before everything else. For an address from image_url the tag also gets a srcset with every rendition of the image, so give it an honest sizes (the width the image takes on the page) and the browser downloads only what the screen needs.

{{ url|image_tag(alt = '', loading = 'lazy', sizes = '100vw', class = null, width = null, height = null, fetchpriority = null) }}

Example:

{{ product.featuredMedia|image_url(width: 800)|image_tag(alt: product.title, loading: 'eager') }}

asset_url

Address of a file in the theme's assets/ directory, by its path inside assets/. The address contains the theme fingerprint, so browsers cache it for a year and a new theme version is fetched right away. A PNG or JPG gets a WebP copy when its file is saved (install, update, upload) and the address points at that copy whenever it is smaller - keep writing 'img/photo.jpg'|asset_url.

{{ 'path/in/assets'|asset_url }}

Example:

{{ 'css/base.css'|asset_url }}

stylesheet_tag

A <link rel="stylesheet"> tag for an address.

{{ url|stylesheet_tag }}

Example:

{{ 'css/base.css'|asset_url|stylesheet_tag }}

script_tag

A deferred <script> tag for an address, a module by default.

{{ url|script_tag(type = 'module') }}

Example:

{{ 'js/theme.js'|asset_url|script_tag }}

t

A translation from the theme's locales/ in the store language, falling back to *.default.json. Parameters replace {{ name }} placeholders in the text.

{{ 'key.path'|t(params = {}) }}

Example:

{{ 'cart.items'|t({ count: cart.itemCount }) }}

handleize

Lowercase, with every run of other characters replaced by a hyphen - Summer Sale! becomes summer-sale.

{{ text|handleize }}

Example:

<div id="tab-{{ group.title|handleize }}">

strip_html

Removes HTML tags and leaves the text.

{{ html|strip_html }}

Example:

{{ product.shortDescription|strip_html|truncate(140) }}

truncate

Cuts text to a number of characters and appends end when it was cut.

{{ text|truncate(length = 120, end = '…') }}

Example:

{{ article.excerpt|truncate(160) }}

Math

plus

Adds a number. Kept for templates ported from Liquid; + works too.

{{ number|plus(other) }}

Example:

{{ forloop_index|plus(1) }}

minus

Subtracts a number.

{{ number|minus(other) }}

Example:

{{ product.compareAtPrice|minus(product.price)|money }}

times

Multiplies by a number.

{{ number|times(other) }}

Example:

{{ item.unitPrice|times(item.quantity)|money }}

divided_by

Divides by a number; dividing by zero gives 0 instead of an error.

{{ number|divided_by(other) }}

Example:

{{ (product.compareAtPrice - product.price)|times(100)|divided_by(product.compareAtPrice)|round }}%

Twig filters

abs

Absolute value.

{{ number|abs }}

batch

Splits a list into chunks of a size - rows of a grid.

{{ list|batch(size, fill = null) }}

capitalize

First letter uppercase, the rest lowercase.

{{ text|capitalize }}

column

Values of one key from a list of hashes.

{{ list|column(name) }}

date

Formats a date - {{ article.publishedAt|date('j F Y') }}.

{{ date|date(format = 'd.m.Y H:i') }}

default

The value, or the fallback when it is empty or undefined.

{{ value|default(fallback = '') }}

e

Alias of escape.

{{ value|e(strategy = 'html') }}

escape

Escapes a value - for html, html_attr, js, css or url. Output is escaped as HTML automatically.

{{ value|escape(strategy = 'html') }}

filter

Keeps the items for which the arrow function is true.

{{ list|filter(v => condition) }}

first

The first item of a list or the first character of a string.

{{ list|first }}

format

sprintf-style formatting.

{{ '%s of %d'|format(a, b) }}

join

Joins a list into a string.

{{ list|join(glue = '', and = null) }}

json_encode

JSON for a value - pass data to a script with |json_encode|e('html_attr') in a data attribute.

{{ value|json_encode }}

keys

Keys of a hash.

{{ hash|keys }}

last

The last item.

{{ list|last }}

length

Number of items or characters.

{{ list|length }}

lower

Lowercase.

{{ text|lower }}

map

Transforms every item with an arrow function.

{{ list|map(v => expression) }}

merge

Merges lists or hashes.

{{ hash|merge(other) }}

nl2br

Line breaks to <br> - for plain text fields shown on several lines.

{{ text|nl2br }}

number_format

Formats a number. Use money for prices.

{{ number|number_format(decimals, point, thousands) }}

raw

Prints without escaping. Only for HTML the platform already sanitised: descriptions, page content, rich text settings.

{{ html|raw }}

reduce

Folds a list into one value.

{{ list|reduce((carry, v) => expression, initial) }}

replace

Replaces substrings.

{{ text|replace({ from: to })) }}

reverse

Reverses a list or a string.

{{ list|reverse }}

round

Rounds a number.

{{ number|round(precision = 0, method = 'common') }}

slice

A part of a list or a string.

{{ list|slice(start, length) }}

sort

Sorts a list.

{{ list|sort((a, b) => a <=> b) }}

split

Splits a string into a list.

{{ text|split(delimiter, limit) }}

striptags

Twig's own tag stripping - same purpose as strip_html.

{{ html|striptags }}

title

Every word capitalised.

{{ text|title }}

trim

Removes whitespace from both ends.

{{ text|trim }}

upper

Uppercase.

{{ text|upper }}

url_encode

Encodes a value for a URL, a hash becomes a query string.

{{ value|url_encode }}