component
Load the header and footer menus and a set of reviews in the browser, for menus and testimonial blocks.
Use Salla.api.component when browser code needs the store's menus or a set of reviews, for example in a block that loads after the page.
For the first render, read menus with the menu API module in a loader instead, so they are in the page from the start.
This module is only on Salla.api, not on Salla directly: write Salla.api.component.getMenus().
const { data: header } = await Salla.api.component.getMenus('header');
const { data: reviews } = await Salla.api.component.getReviews({ type: 'products', items: [12, 15], per_page: 5 });Methods
| Method | Parameters | Returns |
|---|---|---|
getMenus | 'header' or 'footer' (default 'header') | The menu, in the current language |
getReviews | { type?, items?, per_page? } | Reviews. per_page is 5 by default. |
type picks where the reviews come from:
type | items |
|---|---|
all (default), store | Not needed |
products, categories | An array of product or category ids |
json | Needed too: the items to show |
Events
| Event | Fires when | Arguments |
|---|---|---|
component::menus.fetched / component::menus.fetch.failed | getMenus | response or error |
component::reviews.fetched / component::reviews.fetch.failed | getReviews | response or error |
The helpers are Salla.event.component.onMenuFetched and onReviewsFetched, with their off... pairs.
Gotchas
getReviewschecks its input before sending: an unknowntype, orproductswithout an array of ids, rejects at once.- Old Twig examples call
Salla.event.component.reviewsFetched(fn). That fires the event instead of listening to it. UseonReviewsFetched.