Purpose#
The Toast reusable renders the UI container for toast notifications. All toast state and behavior is owned by the global Alpine store $store.toast (defined in Assets/js/theme.js).Many other components/reusables use $store.toast to show success/error/info feedback.Where it's rendered#
This reusable is mounted once in the layout (Structure/LayoutA.liquid):{% render 'Reusables\\Toast\\Default' %}
This reusable is rendered without Liquid parameters.Model shape (storefront example)#
Required: provide a real storefront model sample.To document the contract correctly, we use the real runtime shape of the Alpine toast store (Alpine.store('toast')). The store is code-defined (not delivered as a page model), but the “real” contract is the store object that exists at runtime.Sanitized runtime shape (based on the actual store definition in Assets/js/theme.js) focusing on the fields used by the template:{
"messages": [
{
"id": "Toast Id",
"message": "Sample text",
"iconClass": "ic-check-circle-fill",
"type": "success",
"extraHtml": "<p>Sample extra HTML</p>",
"extraHtmlIndex": 0,
"keepAlive": false
},
...
]
}
What each toast message prop means:Unique identifier generated by the toast store.
Used by the close button ($store.toast.remove(id)) and by the auto-dismiss timer.
The main text shown in the toast (x-text="msg.message").
Optional icon CSS class (e.g. ic-check-circle-fill, ic-warning).
When provided, the icon span is shown and receives this class.
Controls the visual variant class:success → toast__box--success
error → toast__box--error
Optional extra content rendered as HTML (x-html="msg.extraHtml").
Should be considered trusted/sanitized before being passed to the toast store.
Optional number kept on the message object.
The template binds it to data-toast-index on the close button.
It does not affect rendering by itself.
When true, the toast store will not auto-dismiss the message.
When false, the store auto-removes it after 5000ms.
Template behavior (Liquid + Alpine)#
Shows the toast container when $store.toast.messages.length > 0.
Renders one toast per message in $store.toast.messages.
Applies UI variant classes based on message type: Shows an icon when msg.iconClass exists.
Renders main message text from msg.message.
Optionally renders extra HTML when msg.extraHtml exists.
$store.toast.remove(msg.id)
JavaScript#
Reusable JS file#
Reusables/Toast/Default.js defines an empty object:const toastreusabledefault = {};
The reusable itself does not own logic; it’s purely UI.Global Alpine store (the real behavior)#
In Assets/js/theme.js the toast store is defined as:Alpine.store('toast', { ... })
_counter: internal counter
Creates a unique id and pushes a new message to messages.
If keepAlive is false, auto-removes the toast after 5000ms.
Returns the created toast id.
Value stored as msg.message and rendered as plain text.
Value stored as msg.iconClass and applied to the icon span.
Value stored as msg.type and drives the toast__box--* class.
Value stored as msg.keepAlive.
When false, the store schedules auto-dismiss.
Value stored as msg.extraHtml and rendered with x-html.
Value stored as msg.extraHtmlIndex and bound to data-toast-index.
removeAll()#
Clears the messages array.
remove(id)#
Removes a single toast message by id.
Global Alpine stores#
Additionally, other stores interact with toast (notably $store.modal.close() clears toasts if any exist).Services / API calls#
This reusable does not call services.Dependencies#
Liquid: Reusables/Toast/Default.liquid
JS: Reusables/Toast/Default.js
Translations: Reusables/Toast/Default.json
$store.toast (defined in Assets/js/theme.js)
Notes#
Toast rendering uses msg.extraHtml via x-html, so any extra HTML should be trusted/sanitized before being passed to $store.toast.add(...).
The close button binds :data-toast-index="msg.extraHtmlIndex", but removal is performed by msg.id.
Modified at 2026-04-14 13:18:56