1. Hooks
Salla Platform Docs
  • Theme Architecture
    • Layouts
      • Overview
      • Global Variables
      • CSS Variables
      • Custom Fonts
      • Master Layout
      • Salla Icons
      • Hooks
      • Localizations
      • Salla Component Hooks
      • Hooks
        • Overview
        • Template Hooks
        • Component Hooks
    • Pages
      • Home Page
      • Overview
      • Product Pages
        • Products listing
        • Single product
      • Customer Pages
        • Profile
        • Orders list
        • Order details
        • Wishlist
        • Notifications
      • Blog Pages
        • Blog listing
        • Single blog
      • Brand Pages
        • Brands listing
        • Single brand
      • Common Pages
        • Cart
        • Loyalty
        • Thank you
        • Single page
        • Landing Page
    • Components
      • Overview
      • Home Components
        • Youtube
        • Fixed banner
        • Testimonials
        • Parallax background
        • Photos slider
        • Store features
        • Square photos
        • Fixed products
        • Products slider
        • Featured products - Style 1
        • Featured Products - Style 2
        • Featured Products - Style 3
        • Brands
        • Enhanced Square Banners
        • Main Links
        • Enhanced Slider
        • Slider Products with Headers
        • Latest Products
        • Vertical Menu with Slider
      • Product Components
        • Essentials
        • Options
      • Common Components
        • Header Components
        • Footer Components
        • Comments component
  • Requirements & Review
    • Overview
    • Main Requirements
    • Review Process
      • UI / UX Review
      • Technical Review
      • Metadata Review
      • Pre-Launch Review
  • Getting Started
    • Create a theme
    • Setup a theme
    • Develop a theme
    • Publish a theme
  • Files and Folders Structure
    • Directory structure
    • Twilight.json
  • Twig Template Engine
    • Basic syntax
    • Twilight flavoured twig
  • Change Log
Merchant
Merchant
  • Merchant API
  • Embedded SDK
  • Salla OAuth 2.0
Storefront
Storefront
  • Twilight Engine
  • Twilight SDK
  • Web Components
  • Ecommerce Events
  • Component Bundle
  • Checkout APIs
  • Change Log
App Functions
Partner APIs
Partner APIs
  • App API
  • Shipments & Fulfillment APIs
  • Salla AWB
  • Recurring Payments API
  • Billing System Salla partners
  • Communication Apps
Dev Tools
Dev Tools
  • Partners Agent Kit
  • Salla Apps Playbook
  • Salla CLI
Merchant
Merchant
  • Merchant API
  • Embedded SDK
  • Salla OAuth 2.0
Storefront
Storefront
  • Twilight Engine
  • Twilight SDK
  • Web Components
  • Ecommerce Events
  • Component Bundle
  • Checkout APIs
  • Change Log
App Functions
Partner APIs
Partner APIs
  • App API
  • Shipments & Fulfillment APIs
  • Salla AWB
  • Recurring Payments API
  • Billing System Salla partners
  • Communication Apps
Dev Tools
Dev Tools
  • Partners Agent Kit
  • Salla Apps Playbook
  • Salla CLI
Salla - Opensource
Salla - Developers Community
  1. Hooks

Component Hooks

Component Hooks are a JavaScript API that lets app and partner developers safely interact with Salla's web components at runtime. You can hook into a component when it loads, intercept its validation flow, modify its UI, or rewrite a request URL — all from your own script, with no timing worries.
Component Hooks use JavaScript and are meant for app and partner developers. If you are a theme developer looking to inject content into page templates via Twig, see the Template Hooks article instead.

📙 What You'll Learn#

How It Works
Registering a Hook
Available Components & Hooks
Late Registration Support
Hook Options: Priority & Once
Removing a Hook
Component Properties Reference
Real-World Use Cases
Security: The Whitelist System

How It Works#

The hooks system is exposed globally via Salla.hooks and is built around three internal structures:
Store — a Map of registered callbacks, keyed by component tag and hook name.
Whitelist — a Map that defines exactly which hook names are allowed per component tag.
Component History — a Map that records every component element that has loaded on the page, enabling late registration.
When a Salla component mounts on the page, it calls Salla.hooks.registerComponent(tag, element) internally. This fires any already-registered componentDidLoad callbacks for that element and adds it to the history — so any future registrations can also reach it retroactively.
Always wrap your hook registrations inside Salla.onReady() to guarantee the Salla SDK is fully initialized before your code runs.

Registering a Hook#

ParameterTypeRequiredDescription
tagstring✅The component tag name (e.g. 'salla-add-product-button')
hookNamestring✅The hook to subscribe to (e.g. 'componentDidLoad', 'validate')
callbackFunction✅Runs when the hook fires. Receives a context argument depending on the hook.
optionsobject❌{ priority: number, once: boolean } — both optional
Returns: An unsubscribe function. Call it to cleanly remove your hook.

Available Components & Hooks#

salla-add-product-button#

Hook NameWhen CalledContext ReceivedWhat You Can Modify
componentDidLoadWhen the button component finishes renderingelement (HTMLElement)The element and its children
validateDuring the add-to-cart validation flow{ isValid, productId, component }ctx.isValid to block or allow the action

salla-products-list#

Hook NameWhen CalledContext ReceivedWhat You Can Modify
componentDidLoadWhen the list component finishes renderingelement (HTMLElement)The element and its children
beforeBuildListUrlBefore the product fetch URL is built or pagination cursor is consumed{ component, url }ctx.url to rewrite the request URL

Other Whitelisted Components#

The following components currently support componentDidLoad only:
Component TagDescription
salla-product-optionsProduct options selector
salla-products-sliderHorizontal product slider
salla-hookInternal theme slot mounting component
salla-scopesScopes / permissions component
salla-user-menuUser account menu
NOTE
New components and hook names are added with each Twilight release. If you need a hook that isn't listed here, see Requesting New Hooks in the Overview article.

Late Registration Support#

This is one of the most powerful aspects of the system. Your script does not need to load before the components.

The Problem#

In a classic event-driven model, if a component fires its load event before your script is ready, you miss it entirely. This forces brittle load-order dependencies that are hard to maintain.

The Solution#

The hooks system keeps a component history. When you register a componentDidLoad hook, it immediately invokes your callback for every component of that type that has already loaded, then continues firing for future ones.
Here is exactly what happens under the hood:
1
Component Loads
A salla-add-product-button element renders on the page. It internally calls registerComponent(), fires any already-registered componentDidLoad callbacks, and adds itself to the component history.
2
Your Script Loads Later
Your partner script loads — after the component — and calls Salla.hooks.registerHook('salla-add-product-button', 'componentDidLoad', cb).
3
Immediate Catchup
The system checks the component history and immediately calls your callback for every existing salla-add-product-button element on the page.
4
Future Components Covered Too
Any new salla-add-product-button elements that load after your registration will also trigger your callback normally going forward.

Hook Options: Priority & Once#

The optional fourth argument to registerHook() accepts two options.
priority
once

Removing a Hook#

You have three ways to remove hooks depending on how granular you need to be.
Unsubscribe Function
removeHook()
clear()
The cleanest approach — store the return value of registerHook() and call it when done.

Component Properties Reference#

When your callback receives a component object — either directly as element in componentDidLoad or via ctx.component in validate — you have access to the full component instance.
The following properties are available on salla-add-product-button:
Context objects are passed by reference. Modifying ctx.isValid in the validate hook directly affects whether the add-to-cart action proceeds. Be deliberate about what you change.

Real-World Use Cases#

Use Case 1: Subscription Products — Modify UI and Block Re-Purchase
Use Case 2: Booking Permission Check
Use Case 3: Quick Button Text Change
Use Case 4: Rewrite the Products List Fetch URL

Security: The Whitelist System#

Every call to registerHook() is validated against the whitelist before any callback is stored. Two checks must pass:
1.
Is the tag in the whitelist?
2.
Is the hook name allowed for that tag?
If either check fails, the registration is silently ignored and a warning is printed to the browser console. A no-op function is returned instead of a real unsubscribe handle — so your code won't break, but the hook won't do anything.
✅ Valid Usage
❌ Blocked Usage
INFO
To register a new component tag or hook name, edit the _whitelist Map in /packages/twilight/src/lib/hooks.js. See Requesting New Hooks in the Overview article for the full process.

Where to Go From Here#

Next StepDescription
Hooks OverviewGo back to understand how Template and Component Hooks connect
Template HooksExplore server-side Twig hooks for theme developers

Modified at 2026-05-07 11:37:45
Previous
Template Hooks
Next
Home Page