Home
Wiki
Home
Wiki
  1. 3. Reusables
  • Back to home
  • 1. Themes
  • Vs Code
    • Getting Started
  • Kitchenware
    • Layout
      • New Layout
      • Legacy Layout
    • Components
      • Announcement
      • Banner Carousel
      • Banner With Products Carousel
      • Blog Category List
      • Blog List
      • Brand List
      • Brands Carousel
      • Breadcrumb
      • Call To Action
      • Cart
      • Categories List
      • Change Password
      • Checkout
      • Cookie Manager
      • Filter list
      • Footer
      • Forgot Password
      • Form
      • Hero Carousel
      • Icon Block
      • Invitation
      • Last Visited Products
      • Layout
      • Login
      • Map
      • Nav Bar
      • Offer
      • Product Attachments
      • Product Attributes
      • Product Documentation
      • Product Expected
      • Product Modal
      • Products Block
      • Products Carousel
      • Product Single
      • Profile
      • Quote
      • Register
      • Related Products
      • Search
      • Stores
      • Subscribe Newsletter
      • Text with Image
      • Top Bar
      • Video
    • Reusables
      • Getting Started
    • Assets
      • Getting Started
    • SDK
      • Products
        • _findProductsByCategory
        • _findProductsByIds
        • _findProductsByTitle
        • _findProductsByFilter
        • _findProductsByCriteria
        • _findProductsAndCalculate
        • _findProductsThenCalculate
        • _getProductAttributeSet
        • _setLastVisited
      • Categories
        • _findCategoryTreeById
        • _findCategoriesByIds
        • _findCategoryByAlias
        • _findCategoryTreeByAlias
        • _getCategoryContent
      • Collections
        • _getCollectionContent
        • _findCollectionsByIds
        • _findCollectionsByIdsThenCalculate
      • Brands
        • _getBrandContent
        • _findBrandsByIds
      • Cart
        • _addToCartMulti
        • _addToCart
        • _setCart
        • _clearCart
        • _setCartListener
        • _removeFromCart
        • _calculateCart
      • Checkout
        • _startCheckout
        • _updateCheckout
        • _completeCheckout
      • Shopping Lists
        • _getShoppingLists
        • _updateShoppingList
        • _createShoppingList
        • _deleteShoppingList
        • _getShoppingListByAlias
      • Navigation
        • _getFooterMenu
        • _getHeaderMenu
      • Users
        • _getUserById
      • Utils
        • _calculateCurrency
        • _getCurrencySymbol
        • _getCulture
        • _subscribeToNewsletter
        • _findUnitsByIds
  • Noir
    • 0. Introduction
    • 6. FAQ
    • 1. Structure
      • _Overview
      • LayoutA.liquid
      • ComponentsList.liquid
      • Metas.liquid
      • CssVariables.liquid
      • Json.liquid
      • GoogleTagManager.liquid
      • StagingButton.liquid
    • 2. Components
      • _Overview
      • Announcement
      • BannerCarousel
      • BlogCategoryList
      • BlogHighlights
      • BlogList
      • BrandList
      • Breadcrumb
      • Cart
      • CategoriesList
      • ChangePassword
      • Checkout
      • CookieManager
      • CustomTable
      • Faq
      • FilterList
      • Footer
      • ForgotPassword
      • Form
      • IconBlock
      • Invitation
      • LastVisitedProducts
      • Login
      • Map
      • NavBar
      • Offer
      • ProductAttachments
      • ProductAttributes
      • ProductComparison
      • ProductDocumentation
      • ProductMixList
      • ProductsBlock
      • ProductsCarousel
      • ProductSingle
      • Profile
      • Quote
      • Register
      • RelatedProducts
      • SingleBlog
      • Stores
      • TextWithImage
      • ThankYouPage
      • TopBar
      • Wishlist
      • OrderReviews
      • ProductReviews
      • Newsletter
    • 3. Reusables
      • _Overview
      • Addresses
      • AddressForm
      • AnnouncementModal
      • BackToTop
      • BillingRetail
      • BlogPostingStructuredData
      • BrandListStructuredData
      • CollectionStructuredData
      • Company
      • General
      • GroupChildrenTable
      • Login
      • LoginModal
      • MonthlyTransactions
      • Offers
      • Orders
      • Payment
      • ProductAttachments
      • ProductAttributes
      • ProductAvailabilityAction
      • ProductComparisonButton
      • ProductComparisonFloatingButton
      • ProductGridItem
      • ProductGridItemClassic
      • ProductListItem
      • ProductModal
      • ProductStructuredData
      • ProfileInfo
      • PromptModal
      • Quotes
      • Register
      • Services
      • Shipping
      • ShoppingLists
      • ShoppingListsButton
      • ShoppingListsNavbar
      • StoresStructuredData
      • Toast
      • Transactions
      • Users
      • VariantContent
      • VariantContentClassic
      • WishlistButton
      • ProductRating
      • ClientHelpers
      • FaqStructuredData
      • ShoppingAssistant
    • 4. Assets
      • Fonts
      • Images
      • Templates
      • Javascript
        • _Overview
        • theme.js
      • Css - Scss
        • _Overview
        • ThemeClasses
    • 5. SDK
      • _Overview
      • LiquidGlobals
      • ServicesSDK
  1. 3. Reusables

AnnouncementModal

Purpose#

AnnouncementModal is the modal reusable that presents announcements/notifications in a carousel detail view.
It supports manual viewing and homepage auto-open behavior for unread/unviewed announcements.

Where it's rendered#

In Components/Announcement/Default.liquid:
{% render 'Reusables\\AnnouncementModal\\Default', announcements: announcements %}

Inputs (Liquid render parameters)#

Source: Reusables/AnnouncementModal/Default.liquid.
This reusable is initialized via Alpine using:
x-data='announcementmodalreusabledefault.initComponent(
  {{ announcements | serialize }},
  {{ Reusables.AnnouncementModal.Translations.MarkAnnouncementAsReadErrorMessage | serialize }},
  {{ userAuthenticated | serialize }}
)'

Model shape (storefront example)#

Below is a sanitized excerpt from a real Announcement component model dump.
{
  "announcements": [
    {
      "id": "Announcement Id",
      "title": "Sample title",
      "description": "<p>Sample description</p>",
      "buttonPrimaryText": "Sample button text",
      "buttonPrimaryLink": "/sample",
      "isRead": true,
      "triggerEnabled": true,
      "triggerType": "delay",
      "triggerDelaySeconds": 15,
      "triggerScrollPercent": null,
      "image": {
        "id": "Image Id",
        "galleryId": "Gallery Id",
        "link": "https://example.com/sample",
        "mediaType": "Image"
      }
    },
    ...
  ],
  "name": "Announcement",
  "view": "Default",
  "section": "SectionHeader",
  "settings": {
    "id": "Component Id",
    "section": "SectionHeader",
    "type": "NoirAnnouncement",
    "name": "Announcement",
    "configuredInContentApi": true,
    "view": "Default",
    "displayName": "",
    "cssClass": "",
    "header": "",
    "alignment": "Left"
  },
  "translations": {
    "closeAnnouncementsModalMessage": "Sample text",
    "notifications": "Sample text",
    "noNotificationsFound": "Sample text",
    "...": "..."
  }
}

Required fields#

announcements (array)
Used both in Liquid and JS.
Expected fields read in the modal template / JS:
id
title
description (optional)
image.link (optional)
image.alt (optional)
buttonPrimaryText + buttonPrimaryLink (optional)
buttonSecondaryText + buttonSecondaryLink (optional)
isRead (only used when userAuthenticated is true)
triggerEnabled, triggerType, triggerDelaySeconds, triggerScrollPercent (optional, see Display triggers)

Optional fields#

userAuthenticated (boolean)
Passed from Liquid into JS; affects the “read/viewed” logic.
Reusables.AnnouncementModal.Translations.MarkAnnouncementAsReadErrorMessage (string)
Used for the toast shown if marking announcements as read fails.

Template behavior (Liquid + Alpine)#

Source: Reusables/AnnouncementModal/Default.liquid.
Modal visibility is driven by $store.announcementModal.visible.
When the modal closes (@after-leave), it flushes the stored current id:
@after-leave="$store.announcementModal.flush()"
Uses x-init to decide whether it’s:
a “specific announcement” modal (when $store.announcementModal.id is set)
or the homepage auto-open carousel
Renders announcements through a Swiper carousel (#announcements-carousel).

Data contract (JS runtime)#

announcementmodalreusabledefault.initComponent(announcements, markAnnouncementsAsReadErrorMessage)#

Source: Reusables/AnnouncementModal/Default.js.
State:
announcements (input)
displayAnnouncements (derived list shown in swiper)
currentId
carousel (DOM element: #announcements-carousel)

JavaScript#

Source: Reusables/AnnouncementModal/Default.js.

init()#

Initializes the display list using the current $store.announcementModal.id.
Watches $store.announcementModal.id; when it changes to a non-null id, it rebuilds the display list.

init#

Alpine lifecycle method that initializes the display array and wires store watchers for modal id changes.

initDisplayArray(selectedId)#

Builds displayAnnouncements based on context:
Specific announcement (selectedId is truthy)
Finds the matching announcement, sets displayAnnouncements = [match].
Destroys existing swiper (if any) and hides pagination.
Not specific
If not on homepage (window.location.pathname !== "/") it only updates remaining count and exits.
On homepage (/):
If authenticated: uses announcement.isRead to decide what to show.
If anonymous: uses $store.viewedAnnouncements cookie-based list.
If there are remaining announcements, it opens the modal.

swiperInit(isFromSpecific = false)#

Initializes Swiper with pagination and optional looping.
On slideChangeTransitionEnd:
Updates currentId
Adds the id to $store.viewedAnnouncements
If authenticated, tries to mark the announcement as read via markAnnouncementsAsRead(newId)
Updates remaining count.

markAnnouncementsAsRead(ids)#

Only for authenticated users.
Calls:
servicesreusabledefault.setReadAnnouncementIds([ids])
On failure it shows a toast with markAnnouncementsAsReadErrorMessage.

updateRemainingCount()#

Calculates how many announcements are not viewed yet (based on $store.viewedAnnouncements.isViewed(id)).
Writes the result into $store.announcementModal.remainingCount.

Display triggers#

An announcement can be opened by a trigger instead of on page load. A trigger applies only when triggerEnabled is true and triggerType is one of the values below; otherwise the announcement opens on page load as before.
triggerTypeOpens whenSetting
delayThe configured time has passedtriggerDelaySeconds (default 15)
scrollThe visitor has scrolled the configured share of the pagetriggerScrollPercent (1-100, default 50)
exitThe visitor shows intent to leave (see below)none
Exit intent:
Desktop: the cursor leaves through the top of the window, or enters the <header>.
Touch devices: a fast scroll back to the top of the page, or the visitor returns to the tab after switching away.
Behavior:
Triggered announcements are excluded from the page-load list and use the same frequency rules as other announcements (always, session, days), so by default each appears once per session.
Each trigger fires once. If another announcement is already open, the trigger waits and retries every 3 seconds.
Scroll listeners are passive and throttled with requestAnimationFrame.
The methods are hasTrigger(a), setupTriggers(), setupExitIntent(a) and fireTrigger(a).

updateRemainingCount#

Global Alpine stores#

Directly used:
$store.announcementModal
visible, id, remainingCount
open(id), close(), flush()
$store.viewedAnnouncements
addViewedId(id)
isViewed(id)
$store.toast
Used for error reporting when marking as read fails.
Indirectly involved (frame-level UX):
$store.announcements
Announcement list uses this store; announcementModal.close() may reopen it depending on cookie-manager state.

Services / API calls#

servicesreusabledefault.setReadAnnouncementIds([id]) (authenticated only)

Dependencies#

Reusables/AnnouncementModal/Default.liquid
Reusables/AnnouncementModal/Default.js
Reusables/AnnouncementModal/Default.json (translations)
Components/Announcement/Default.liquid (render site)
Swiper (vendor lib, used via new Swiper(...))
$store.announcementModal, $store.viewedAnnouncements, $store.toast, $store.announcements in Assets/js/theme.js

Notes#

The reusable relies on the global variable userAuthenticated (used in both Assets/js/theme.js stores and in Reusables/AnnouncementModal/Default.js).
Homepage auto-open behavior:
The modal auto-opens only on /.
Authenticated users: it shows only !announcement.isRead items.
Anonymous users: it shows items not in the session cookie viewed_announcements.
“Viewed vs read”:
“Viewed” is always tracked locally via $store.viewedAnnouncements.
“Read” is a server-side/authenticated concept updated via setReadAnnouncementIds.

Examples#

Render from Announcement component:
{% render 'Reusables\\AnnouncementModal\\Default', announcements: model.announcements %}
Modified at 2026-11-17 10:34:58
Previous
AddressForm
Next
BackToTop
Built with