Skip to main content
Version: 2.0.0

Twig Reference

yStore adds a set of Twig functions and filters to the standard Craft CMS template environment. This page is your starting point — use it to find what's available and when to use it.

Functions (via craft.yui)

Access yStore functions through the craft variable in any Twig template.

Product functions

FunctionReturnsDescription
craft.yuiProducts(select, criteria, orderBy, limit, with)ProductQueryQuery products with field selection, filtering, and eager loading
craft.getProduct(entry)Product|nullResolve a product from a linked element
craft.getVariant(criteria)Variant|nullFetch a variant by criteria
craft.getProductByVariantSku(sku)Product|nullFind a product by variant SKU
craft.getProductUrlById(id)stringGet a product's URL by ID
craft.getYuiProductAddToAction()stringURL for the add-to-cart action
craft.getYuiClearCartAction()stringURL for the clear-cart action

Cart functions

FunctionReturnsDescription
craft.getCartItems()arrayCurrent cart items
craft.getCartTotals()arrayCart total rows (subtotal, tax, shipping, grand total)
craft.isAjaxCartEnabled()boolWhether the AJAX cart is enabled
craft.isAddToCartPopupEnabled()boolWhether the add-to-cart popup is active
craft.isMinicartSidebarEnabled()boolWhether the minicart sidebar is enabled

Customer & session functions

FunctionReturnsDescription
craft.shopCustomerIsLoggedIn()boolWhether a customer is logged in
craft.customerRegistrationPasswordIsRequired()boolPassword required on registration
craft.customerSubscriptionEnabled()boolNewsletter subscription feature active
craft.customerWishlistEnabled()boolWishlist feature active

Site & store functions

FunctionReturnsDescription
craft.getSiteCurrency()stringCurrency code (e.g. EUR)
craft.getSiteCurrencySign()stringCurrency symbol (e.g. )
craft.getSiteLanguage()stringActive language code
craft.getTaxPriceDisplayType()stringincl or excl
craft.canViewPrices()boolWhether current visitor can see prices
craft.getCountries()arrayAvailable countries list

Rendering & asset functions

FunctionReturnsDescription
craft.getCssLink(path, version)string<link> tag with optional cache-bust version
craft.getCssStyleContent(path)stringInline critical CSS content
craft.renderFormToken()stringAsync CSRF token <script> tag
craft.getTotalLabels()arrayOrdered cart/checkout total label definitions
craft.getSectionData()arraySection data for customer-specific content
craft.formatAddress(address)stringFormat an address object into readable text
Full function reference

For complete parameter signatures and return types, see Craft Behaviors.

Filters

Use these as Twig filters: {{ value|filterName }} or as functions: {{ filterName(value) }}

FilterDescriptionExample
formatPriceFormat a number as a price with currency{{ product.price|formatPrice }}
formatDateFormat a date/time string{{ order.createdAt|formatDate('d.m.Y') }}
createSlugCreate a URL-safe slug from a string{{ title|createSlug }}
buildQueryParamsBuild a query string with existing URL params{{ '/products'|buildQueryParams({page: 2}) }}
isArrayTest if a value is an array{% if items|isArray %}
uniqueRemove duplicates from an array{{ items|unique }}
base64_encodeEncode a string as Base64{{ token|base64_encode }}

Pricing helpers (in templates)

When you have a product object, use these helpers for correct price display:

{# Recommended — respects tax display settings #}
{{ product.getPrice()|formatPrice }}
{{ product.getFinalPrice()|formatPrice }}
{{ product.getSpecialPrice()|formatPrice }}

{# Check sale state #}
{% if product.isOnSale() %}
<s>{{ product.getOriginalPrice()|formatPrice }}</s>
{{ product.getFinalPrice()|formatPrice }}
{% endif %}
Use helpers, not raw fields

Always use getPrice(), getFinalPrice(), etc. instead of accessing raw price fields directly. The helpers respect the store's tax display settings (incl./excl. tax) and customer group pricing.

Product query pattern

{% set products = craft.yuiProducts(
['id', 'title', 'uri', 'yuiPrice'],
{ enabled: true },
{'id': 'desc'},
16,
['productMediaAsset']
).cache(900).all() %}

{% for product in products %}
<a href="{{ product.uri }}">{{ product.title }}</a>
<span>{{ product.getFinalPrice()|formatPrice }}</span>
{% endfor %}