BigCommerce’s Widgets API allows you to create, manage, and apply widgets to your storefront.
In this tutorial, you will create a widget (GitHub) that displays a row of three images and place that widget in a designated region on a category page of BigCommerce’s Cornerstone theme.
access_token with content modify scope.To edit and preview theme files locally, we recommend using Stencil CLI, BigCommerce’s powerful theme development and deployment tool.
For a widget to appear on a store’s page, you have to place it in a region. Regions are added and removed at the file level by editing a page’s template.
Let’s start by adding a new region called category_header_banner to your store’s category page template. You will use this region to position your widget later.
In templates/pages/category.html, add a new region {{{region name="category_header_banner"}}} below the page heading.
If you are using Stencil CLI and editing theme files locally, run a stencil push command to apply your changes before proceeding to the next step. stencil push will bundle your theme into a zip file and upload the zip to BigCommerce. You can find more information on Stencil CLI commands in our Stencil CLI Option and Commands article.
templates/pages/ folder.To verify region creation, send a GET request to /v3/content/regions?template_file=pages/category. Make sure to specify the template_file=pages/category query string parameter to get the category template’s regions.
Look for the region’s name in the response.
Widgets derive from widget templates. Before you can create a widget, you must first create its template. To do so, send a POST request to /v3/content/widget-templates.
Response:
uuid of the widget template in the response. You will use it to create the widget in the next step.To create a widget, use the widget template uuid from the previous step. Send a POST request to /v3/content/widgets making sure to replace the widget_template_uuid placeholder value with your template’s uuid.
Make a note of the widget’s uuid in the response. You will use it to create a placement in the next step.
In the control panel UI, users can drag and drop widgets to place them in a region on a page. For this tutorial, we will use the Widgets API to place the widget programmatically.
To place your widget in the category_header_banner region of a category page, send a POST request to /v3/content/placements.
entity_id depends on the type of page; for example, for product pages, it is the product ID, and for category pages, it is the category ID. To place your widget on a specific category page, you need to provide a category ID. To retrieve available category IDs, send a GET request to /v3/catalog/categories. If you omit entity_id; the widget will appear on all category pages.
It is possible to place a widget on a custom template. Just like with other pages, you must first add a region and then create a placement for your widget as described in Create a region and Create a placement steps, respectively.
In this section, you will create a custom category template which you can then use to place your widget.
/templates/pages folder, create a /custom/category folder and add a custom-category.html file.
Add template content and a new region. (You can copy the content from category.html.)
Open the config.stencil.json file and update the custom-category.html property. The URL you define in config.stencil.json will be used for category mapping.
If using Stencil CLI, push and apply your changes.
POST request to /v3/catalog/categories. Use the URL defined in the config.stencil.json category mapping. In our example, it is /custom-widget-templates/.BigCommerce’s Page Builder tool allows you to customize different style elements of your theme in the store’s control panel. You can use Page Builder to configure and place widgets onto pages to tailor your storefront. To make your widget compatible with Page Builder, add custom configuration settings to the widget template by including the schema property in the create widget template request.
The following is an example of a widget template compatible with Page Builder.
To learn more about Page Builder, see Page Builder Overview.