Skip to main content

Widget Query Functions

Functions for querying the widget registry. All imported from @evershop/evershop/lib/widget.

Import

import {
getAllWidgets,
getEnabledWidgets,
getWidget,
hasWidget
} from '@evershop/evershop/lib/widget';

Functions

getAllWidgets

getAllWidgets(): Widget[]

Returns all registered widgets (both enabled and disabled).

warning

After the first call to getAllWidgets(), the widget manager becomes read-only. No new widgets can be registered.

getEnabledWidgets

getEnabledWidgets(): Widget[]

Returns only widgets where enabled === true.

getWidget

getWidget(widgetType: string): Widget | undefined

Returns a single widget by its type identifier.

hasWidget

hasWidget(widgetType: string): boolean

Checks if a widget with the given type is registered.

Examples

import { getEnabledWidgets, getWidget, hasWidget } from '@evershop/evershop/lib/widget';

const widgets = getEnabledWidgets();
console.log(`${widgets.length} widgets available`);

if (hasWidget('collection_products')) {
const widget = getWidget('collection_products');
console.log(widget.name); // 'Collection products'
}

See Also