You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A storefront widget is a JavaScript component that handles the behavior of a content type after being rendered on the storefront. For example, the Tabs and Sliders use their own storefront widgets to handle the end-user's tapping of tabs and the swiping of slides.
3
+
A storefront widget is a JavaScript component that handles the behavior of a content type after Page Builder renders it on the storefront.
4
+
For example, the Tabs and Sliders have their own storefront widgets to handle the end-user's tapping of tabs and swiping of slides on the storefront.
5
+
However, Page Builder also executes storefront widgets on the Admin stage for block and dynamic block content types.
6
+
This allows end-users to preview how Page Builder will render the blocks and dynamic blocks on the storefront.
4
7
5
8
Adding a storefront widget to your content type is a simple two-step process:
6
9
7
-
8
-
9
10

10
11
11
-
12
-
13
12
## Step 1: Create the JavaScript
14
13
15
14
Name your JavaScript file `widget.js` and put it in the following directory structure: `/view/base/web/js/content-type/{content-type-name}/appearance/{appearance-name}/widget.js`. An example from the PageBuilderQuote content type follows:
16
15
17
16
{:width="477px" height="auto"}
18
17
19
-
The JavaScript for the widget can handle events, initialize third-party controls, or do whatever else you need in order to control your content type's behavior after Page Builder renders the master format template on the frontend.
18
+
The JavaScript for the widget can handle events, initialize third-party controls, or do whatever else you need to control your content type's behavior _after_ Page Builder renders the master format template on the frontend (or within a block or dynamic block on the Admin stage).
20
19
21
20
```javascript
22
21
define([
@@ -33,29 +32,24 @@ define([
33
32
34
33
## Step 2: Configure the widget initializer
35
34
36
-
To configure your `widget.js`to so that Page Builder can initialize and load it on the storefront, create a new `WidgetInitializerConfig` type in your module's `etc/di.xml` file. An example of the initializer from the PageBuilderQuote module follows:
35
+
To configure your `widget.js` so that Page Builder can initialize and load it, create a new `WidgetInitializerConfig` type in your module's global `di.xml` file (`etc/di.xml`). Then add your custom configuration (that includes your widget) as a replacement argument. The following example is from the PageBuilderQuote module:
The XML configuration loads the widget on the frontend, and on the stage, so you can preview content inside both the block and dynamic block content types.
57
-
58
-
**[I don't understand the reference to blocks and dynamic blocks in the previous sentence.]**
59
-
60
-
**[Can you briefly explain how Page Builder loads the widget on the frontend using this `di.xml` file? Thanks.]**
61
-
55
+
That's it! For more examples, look at several of Page Builder's native widget implementations within `app/code/Magento/PageBuilder/view/base/web/js/content-type/`.
0 commit comments