Filters
Every filter a Sworen theme can use, with its arguments.
A filter transforms the value on its left: {value | filter}, or {value | filter(argument, …)}. Filters chain from left to right.
Sworen filters
Section titled “Sworen filters”| Filter | Arguments | Gives |
|---|---|---|
money |
— | {product.price | money} → 349.00 MAD |
money_without_trailing_zeros |
— | 349 MAD when there are no cents, otherwise the same as money |
money_without_currency |
— | 349.00 |
image_url |
width, height (optional) |
An image URL, resized on the server when you give a size: {product.featured_image | image_url(600)} |
image_tag |
alt, width, class, loading (all optional) |
A complete <img>: {product.featured_image | image_tag(product.title, 600, 'card__img')}. loading is lazy unless you pass 'eager'; with no alt, the image’s own alt text is used |
asset_url |
— | The URL of a file in your theme’s assets/: {'base.css' | asset_url} |
stylesheet_tag |
— | <link rel="stylesheet"> for a URL: {'base.css' | asset_url | stylesheet_tag} |
script_tag |
— | <script defer> for a URL |
placeholder_svg_tag |
— | A grey image placeholder; the value is its CSS class: {'card__img' | placeholder_svg_tag} |
t |
variables (optional) |
A translation from your theme’s locales/ (see below) |
date |
format (optional) |
A date with %-tokens: {review.created_at | date('%d/%m/%Y')} |
handleize |
— | A URL-safe slug: My Product → my-product |
url_encode |
— | Text made safe for a URL, e.g. for a WhatsApp link |
json |
— | The value as JSON, safe to put in an HTML attribute or <script> |
All amounts in Sworen are in minor units (cents): 34900 is 349.00. Always print prices through a money filter.
Translations with t
Section titled “Translations with t”t looks a key up in your theme’s locale file for the store’s language (locales/fr.json or locales/en.json), then in locales/en.json. Keys can be nested with dots. When there is no translation, the text itself is printed, so a plain sentence also works as a key.
{ "cart": { "add": "Ajouter au panier", "count": "{{ count }} article(s)" }}<button>{'cart.add' | t}</button><span>{'cart.count' | t({ count: cart.count })}</span><p>{'Livraison gratuite' | t}</p>{{ name }} inside a translation is replaced by the matching variable you pass.
Standard filters
Section titled “Standard filters”These come with the Liqx language. Each also has a camelCase spelling (divided_by and dividedBy).
| Group | Filters |
|---|---|
| Text | append, prepend, capitalize, upcase, downcase, truncate, truncatewords, replace, replace_first, replace_last, remove, remove_first, remove_last, split, slice, strip, lstrip, rstrip, squish, strip_html, strip_newlines, newline_to_br, slugify, escape, escape_once, url_decode, default |
| Numbers | plus, minus, times, divided_by, modulo, abs, round, ceil, floor, at_least, at_most, format |
| Lists | first, last, size, join, concat, reverse, sort, sort_natural, uniq, compact, map, where, reject, find, find_index, group_by, sum, has |
{product.title | truncate(40)}{product.vendor | default(shop.name)}{collection.products | map('title') | join(', ')}{search.terms | escape}