Widget Templates
Widget templates are reusable Handlebars-enabled HTML templates which define the structure of the widget on a page. You can use built-in Handlebars helpers such as {{if}} and {{each}} to add conditional logic to a widget template. Widget templates can be reused to build multiple widgets.
Markup and Schema
A widget template is made up of two parts that are defined together:
- Markup is the
templateproperty. It holds the HTML and Handlebars that determine what the widget renders on the storefront. - Schema is the
schemaproperty. It is JSON that describes the settings, such as text fields, images, and colors, that an editor presents to the store user for configuring the widget.
Because both parts live in the same widget template, the template does two jobs. It is what widgets are created from, and it is what gives the visual editors their controls for how and what a widget displays. You define the template once with the Widgets API, and both of Stencil’s visual editors, Page Builder and Makeswift, can use its markup and schema, so store users can work with it from whichever editor their storefront uses.
The widget template you build in this module’s lab is static. It has markup but an empty schema, so it renders the same content every time and offers the editors no settings to configure. The next module focuses on the schema, adding settings and Handlebars variables to make a widget template’s content configurable.
There is a limit of 1000 custom widget templates per store.
For the endpoints used to create, retrieve, update, and delete widget templates, see the Widgets API reference.