Important: This namespace is available only in Wix Blocks widget code.
Blocks widgets can expose a widget API, letting you add properties, events, and functions to your widget.
The $widget
namespace provides functionality for working with your widget's API from within the widget code.
Sets or gets the widget's properties.
The props
property is an object containing all of the widget's properties.
$w("#text1").text = $widget.props.shoe.size; // "43"
Fires an event that is defined in the Widget API.
The fireEvent()
function fires a widget event, which can then be handled from outside the widget (by code in a parent widget or a site page).
When using the widget's API, the event is named on
, for example, onAddedToCart
.
function fireEvent(eventName: string, data: object): void;
The name of the event to be fired.
A data object that is passed to the event handler.
$w(`#button1`).onClick(() => {
$widget.fireEvent(`addedToCart`, {
productId: product.id,
customerId: customer.id,
});
});