Skip to content
shopdepot.dev

Reference

Functions

Every function a theme can call: rendering blocks, snippets and widgets, platform components, data queries and store addresses.

View as Markdown

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

Functions are called on their own: {{ content_for('blocks') }}. Data functions always read the current store, so a section never sees another store's data.

Rendering

content_for

Renders the blocks of the current section or block, in the merchant's order. Use it where the blocks go; the platform adds the editor attributes and the block wrappers.

{{ content_for('blocks') }}

Example:

<div class="hero__content">{{ content_for('blocks') }}</div>

render

Renders a snippet by file name. The snippet sees only the variables you pass plus the globals shop, settings and cart - variables of the calling file do not leak in. A missing snippet renders nothing.

{{ render('snippet-name', variables = {}) }}

Example:

{{ render('product-card', { product: item, show_rating: true }) }}

render_widget

Renders a widget from a widget setting, or by its handle or placement name. An empty placement renders nothing.

{{ render_widget(widget) }}

Example:

{{ render_widget(section.settings.testimonials) }}

sections

Renders a section group - sections/<name>.json. Used in the layout for the header and the footer.

{{ sections('header-group') }}

Example:

{{ sections('footer-group') }}

placeholder_svg

A neutral SVG placeholder for an empty image slot in the editor.

{{ placeholder_svg(name = 'product', class = null) }}

Example:

{{ placeholder_svg('image', 'card__placeholder') }}

Platform components

cart_summary

The cart summary of the platform: coupon, discounts, delivery from the cheapest method, total, VAT line and the checkout button. Use it on the cart page and style its sd-cart-summary__* classes.

{{ cart_summary() }}

Example:

<aside class="cart__summary">{{ cart_summary() }}</aside>

form

A platform form. Today contact: fields, consents, validation and sending are the platform's; the theme passes CSS classes, the button label, and optionally a fixed subject, which optional fields to show and extra fields. See Platform pages and components.

{{ form('contact', options = {}) }}

Example:

{{ form('contact', { submit: 'Send message' }) }}

Data

query_products

Offers of the current store for a section that is not given a list by the page. Sources - newest (the default), bestsellers (units sold in 90 days, filled up with newest offers), top_selling (only offers that sold - for a "Bestseller" badge), sale and preorder (offers with a variant in pre-order, the nearest shipping date first). category narrows any source to a store category (an object from a setting, an id or a handle).

{{ query_products(source = 'newest', category = null, limit = 8) }}

Example:

{% for product in query_products('bestsellers', null, 4) %}{{ render('product-card', { product: product }) }}{% endfor %}

query_posts

The latest published blog posts, optionally from a blog category path, without a post handle.

{{ query_posts(limit = 3, category = null, exclude = null) }}

Example:

{% for article in query_posts(3) %}{{ render('article-card', { article: article }) }}{% endfor %}

query_post

One published post by its handle, or null.

{{ query_post(handle) }}

query_terms

Values of a dictionary feature by the address of its feature page - all, or only the listed handles; with_image keeps values with a picture in this store; order is name or offers.

{{ query_terms(feature, limit = 12, handles = null, with_image = false, order = 'name', exclude = null) }}

Example:

{% for brand in query_terms('brands', 12, null, true) %}…{% endfor %}

query_categories

Subcategories of a category, or the top-level categories of the store without a parent.

{{ query_categories(parent = null, limit = 12) }}

Example:

{% for category in query_categories(null, 6) %}…{% endfor %}

product_terms

The values of a dictionary feature on one offer - authors under a title, for example.

{{ product_terms(product, feature) }}

Example:

{% for author in product_terms(product, 'authors') %}<a href="{{ author.url }}">{{ author.title }}</a>{% endfor %}

query_term_products

Other offers sharing a dictionary value with this offer - "More from this author".

{{ query_term_products(product, feature, limit = 8) }}

Addresses

url_for

A store address, with the trailing slash every store address has. Routes - home, cart, search, account, wishlist, blog, and with a handle - product, category, article, page.

{{ url_for(route, params = {}) }}

Example:

<a href="{{ url_for('cart') }}">Cart</a>

Twig functions

date

A date object to compare with or format.

{{ date(value = 'now') }}

include

Includes another theme file with the current variables. Prefer render(), which isolates variables.

{{ include(template, variables = {}) }}

max

The largest value.

{{ max(a, b, …) }}

min

The smallest value.

{{ min(a, b, …) }}

random

A random item. Avoid it in cached markup: the page is built once and shown to everyone.

{{ random(values) }}

range

A list of numbers - {% for i in range(1, 5) %}.

{{ range(low, high, step = 1) }}