1. Layouts
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. Layouts

Salla Component Hooks

The Salla Component Hooks System is a JavaScript API that lets developers work with Salla’s web components at runtime, like changing the UI, intercepting validation, and tracking lifecycle events. It does all this without touching core theme code or worrying about when scripts load.
Timing Independent
Register hooks before or after components load. The system handles both cases automatically.
Whitelist Secured
Only approved hook names are accepted. Unauthorized registrations are blocked with a console warning.
Error Isolated
Errors in your callback never crash the core component. Partner code fails safely.
No Duplicates
Components are tracked in a Set, the same element never triggers your hook twice.

Template Hooks vs. Component Hooks | What's the Difference?#

Salla provides two distinct hook systems. Knowing which one you need saves a lot of confusion:
Template HooksComponent Hooks
Syntax{% hook 'head:start' %} (Twig)Salla.hooks.registerHook(...) (JavaScript)
SideServer-sideClient-side (runtime)
PurposeInject HTML into page template slotsInteract with rendered web components
Used in.twig theme filesin scripts / JS integrations
If you are editing .twig template files, you want the Template Hooks article. If you are writing a partner script or JavaScript integration, you are in the right place.

📙 What You'll Learn#

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

How It Works#

The hooks system lives at 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, it calls Salla.hooks.registerComponent(tag, element), which triggers any existing componentDidLoad callbacks and stores the element in history. This allows future hook registrations to access 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
Other Whitelisted Components

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:
When you receive { isValid, productId, component } in the validate hook, modifying ctx.isValid affects whether the add-to-cart action is allowed to proceed. Be deliberate.

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
The Solution
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.

Hook Options: Priority & Once#

The optional fourth argument to registerHook() accepts two options.
Priority
Once
Controls execution order when multiple callbacks are registered for the same hook. Higher values run first. Default is 0.

Removing a Hook#

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

Real-World Use Cases#

Use Case 1: Subscription Products | Modify UI and Block Re-Purchase
The full integration pattern. Listens for a Product Viewed analytics event, then registers both a UI hook and a validation hook for that specific product.
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 ignored and a warning shows in 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
Modified at 2026-06-03 08:07:40
Previous
Localizations
Next
Overview