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

MethodParametersReturns
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:

typeitems
all (default), storeNot needed
products, categoriesAn array of product or category ids
jsonNeeded too: the items to show

Events

EventFires whenArguments
component::menus.fetched / component::menus.fetch.failedgetMenusresponse or error
component::reviews.fetched / component::reviews.fetch.failedgetReviewsresponse or error

The helpers are Salla.event.component.onMenuFetched and onReviewsFetched, with their off... pairs.

Gotchas

  • getReviews checks its input before sending: an unknown type, or products without 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. Use onReviewsFetched.

See also

On this page