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
| Function | Returns | Description |
|---|---|---|
craft.yuiProducts(select, criteria, orderBy, limit, with) | ProductQuery | Query products with field selection, filtering, and eager loading |
craft.getProduct(entry) | Product|null | Resolve a product from a linked element |
craft.getVariant(criteria) | Variant|null | Fetch a variant by criteria |
craft.getProductByVariantSku(sku) | Product|null | Find a product by variant SKU |
craft.getProductUrlById(id) | string | Get a product's URL by ID |
craft.getYuiProductAddToAction() | string | URL for the add-to-cart action |
craft.getYuiClearCartAction() | string | URL for the clear-cart action |
Cart functions
| Function | Returns | Description |
|---|---|---|
craft.getCartItems() | array | Current cart items |
craft.getCartTotals() | array | Cart total rows (subtotal, tax, shipping, grand total) |
craft.isAjaxCartEnabled() | bool | Whether the AJAX cart is enabled |
craft.isAddToCartPopupEnabled() | bool | Whether the add-to-cart popup is active |
craft.isMinicartSidebarEnabled() | bool | Whether the minicart sidebar is enabled |
Customer & session functions
| Function | Returns | Description |
|---|---|---|
craft.shopCustomerIsLoggedIn() | bool | Whether a customer is logged in |
craft.customerRegistrationPasswordIsRequired() | bool | Password required on registration |
craft.customerSubscriptionEnabled() | bool | Newsletter subscription feature active |
craft.customerWishlistEnabled() | bool | Wishlist feature active |
Site & store functions
| Function | Returns | Description |
|---|---|---|
craft.getSiteCurrency() | string | Currency code (e.g. EUR) |
craft.getSiteCurrencySign() | string | Currency symbol (e.g. €) |
craft.getSiteLanguage() | string | Active language code |
craft.getTaxPriceDisplayType() | string | incl or excl |
craft.canViewPrices() | bool | Whether current visitor can see prices |
craft.getCountries() | array | Available countries list |
Rendering & asset functions
| Function | Returns | Description |
|---|---|---|
craft.getCssLink(path, version) | string | <link> tag with optional cache-bust version |
craft.getCssStyleContent(path) | string | Inline critical CSS content |
craft.renderFormToken() | string | Async CSRF token <script> tag |
craft.getTotalLabels() | array | Ordered cart/checkout total label definitions |
craft.getSectionData() | array | Section data for customer-specific content |
craft.formatAddress(address) | string | Format 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) }}
| Filter | Description | Example |
|---|---|---|
formatPrice | Format a number as a price with currency | {{ product.price|formatPrice }} |
formatDate | Format a date/time string | {{ order.createdAt|formatDate('d.m.Y') }} |
createSlug | Create a URL-safe slug from a string | {{ title|createSlug }} |
buildQueryParams | Build a query string with existing URL params | {{ '/products'|buildQueryParams({page: 2}) }} |
isArray | Test if a value is an array | {% if items|isArray %} |
unique | Remove duplicates from an array | {{ items|unique }} |
base64_encode | Encode 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 %}