Functions Available in Templates
The functions a theme can call, grouped by what they are for, with the ones that matter most called out.
Around forty five functions are available in any theme template. These are the ones you will actually use.
Money and Formatting
| Function | Does |
|---|---|
money(amount) |
Formats in the shop's currency |
price(product) |
What this shopper pays, including group pricing |
currency_format(amount) |
Lower level formatting |
local_date(date, format) |
Formats for the shopper's locale |
local_number(n) |
Number formatting |
number_format(n, decimals) |
Explicit formatting |
round(n, precision) |
Rounding |
Use money(), never your own formatting
It handles the shop's currency, the symbol, which side it goes on, and the shopper's market. A hardcoded dollar sign is the single most common fault in a submitted theme, and it is invisible to the developer because it only shows up for the merchant's overseas customers.
The same applies to price(). Printing product.price directly ignores group pricing, so a wholesale customer sees the retail price on your listing and the trade price at checkout, and writes to the merchant about it.
It also ignores a price the shop has fixed for the market being browsed. A merchant can now set an exact price per market rather than having it converted at the daily rate, and display_price already accounts for that. Never convert a price yourself in a template. A theme doing its own arithmetic on product.price turns a price the merchant typed deliberately back into one that moves every morning, which is the thing they set it to avoid.
Catalogue
| Function | Does |
|---|---|
featured_products(ids, limit, source) |
A row of products. source is featured, new or bestselling |
active_categories() |
Categories for navigation |
group_price(product) |
The price for this shopper's group, for one of the thing |
quantity_breaks(product) |
The shopper's quantity ladder, cheapest rung last, as [{from, price}]. Empty where the product has no breaks |
product_image_swaps(product) |
Which photograph belongs to each variant and option choice, and the urls of only those images |
is_wholesale_customer() |
Whether this shopper is trade |
customer_in_group(group) |
Membership test |
quantity_breaks is worked out by asking the price resolver what each threshold costs rather than reading the price rows, so the ladder on the page is the arithmetic the basket will do. A rung that does not beat the one below it is left out. Render it with components/storefront/quantity-breaks.twig or build your own from the array.
product_image_swaps returns {variants: {id: mediaId}, options: {"fieldId:value": mediaId}, urls: {mediaId: {medium, full}}}. Every id is checked against the product's own images, so one assigned and later deleted drops out. Themes do not usually call it directly: include components/storefront/option-image-swap.twig and declare the gallery, which Theme templates describes.
Content
| Function | Does |
|---|---|
navigation_menu(location) |
A menu the merchant built |
recent_blog_posts(limit) |
Posts from the built-in blog |
reading_time(html) |
Minutes to read an article, at 200 words a minute. Null when empty |
external_blog_posts(limit) |
Posts from a blog hosted elsewhere |
upcoming_events(limit) |
Events |
render_form(slug) |
A form the merchant built |
external_links(html) |
Makes links in merchant-written content open safely |
Run merchant-written HTML through external_links() rather than printing it raw. It is what stops a pasted link opening in the same window and losing the shopper.
Sections
Everything a section partial needs. Use these rather than writing the same logic per section: a tint chosen on one section has to come out the same color as a tint chosen on another, or a page looks accidental and the merchant cannot say why.
| Function | Does |
|---|---|
section_style(settings, spacing, background) |
The whole style attribute for a section: padding above and below, and the background. The last two arguments are the defaults to use when the merchant has chosen nothing |
section_box(settings) |
Where a section that is not full width sits across the page, from its box_align. Empty for centered |
section_background(settings) |
Just the background, where a partial needs it apart from the padding |
section_partial(type) |
The partial a section type draws from, read from the manifest. Use it to render a section nested inside another |
gift_card_options() |
What the gift card form needs, and whether the shop sells them at all |
content_places_form(html) |
Whether merchant-written content already places a form with a token, so a template does not draw a second one below it |
{% set s = section.settings|default({}) %}
<section style="{{ section_style(s) }}">
<div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8" style="{{ section_box(s) }}">
...
</div>
</section>
Filters
| Filter | Does |
|---|---|
rich_content |
Merchant-written HTML, with editor images resolved and {form, slug} tokens expanded. Use it for anything a merchant typed |
shop_date, shop_time, shop_datetime |
Formatted in the shop's own date and time settings, not the server's |
Shop and Settings
| Function | Does |
|---|---|
store_name() |
The shop's name |
theme_config(key) |
A theme setting |
theme_has(path) |
Whether this theme ships a file, so an optional template can fall back |
tenant_setting(key, default) |
A shop setting |
language_config() |
Active languages |
markets() |
Configured markets |
countries() |
Country list for forms |
weight_unit(), dimension_unit() |
The shop's units |
cookie_consent() |
What the shopper has agreed to be tracked with |
cookie_consent()
Returns enabled, decided, analytics, marketing and signal. Where the shop has the banner switched off it reports everything allowed, so a template that respects it behaves exactly as before for shops outside a consent regime.
You do not need this for Analytics, Tag Manager or the pixel: the shared partials/analytics.twig already gates those and draws the banner. You need it if your theme adds a script of its own that sets a cookie or reports a visit.
{% if cookie_consent().analytics %}
{# your own measurement goes here #}
{% endif %}
Gating without a way to answer is worse than not gating
The banner lives inside partials/analytics.twig, which every theme includes. Gate your script somewhere that file is not included and the shopper has no way to agree, so your script is silently dead rather than visibly off.
Customer
auth_check(), auth_guest(), auth_user(), auth_guard().
Use auth_check() to vary what is shown, never to hide something that should be protected. Anything that must not be seen is kept off the page by the shop, not by a template condition.
Assets and Plumbing
| Function | Does |
|---|---|
cdn_asset(path) |
An asset through the CDN |
storage_url(path) |
An uploaded file |
csrf_field() |
The token for a form |
app_scripts() |
Scripts registered by installed apps |
translate(key) |
A translated string |
Call app_scripts() in your layout
Apps a merchant installs register scripts here. A theme that never calls it silently breaks every app they bought, and the merchant will report it as the app being broken rather than the theme.
Plugin Hooks
plugin_hook(name), plugin_render(name), plugin_has(name).
Call plugin_hook() at the obvious extension points: above and below the product description, in the basket, at the top and bottom of the checkout, in the footer. Each one is somewhere an installed app can appear.
A theme with no hooks is a theme that quietly breaks the things a merchant adds to their shop.
Checkout and Payments
payment_gateway_components(), payment_gateway_component(gateway), express_checkout_data(), pay_later_data().
Do not rebuild the checkout casually
These render the live payment forms for whichever gateways the merchant has enabled. If you customise the checkout, test every gateway, including the wallet buttons, which only appear on devices that support them. A checkout that works with one processor and silently breaks another is worse than one you left alone.
Requests and Translation
request(), request_get(key), input_get(key), old(key), config(key), csrf_field(), translate(key).
Wrap every piece of text a shopper reads in translate(), even in a theme that ships in one language. Retrofitting it later means touching every template.
