Skip to content

Commit bfed3f8

Browse files
committed
MAGEDOC-3430: Clarify Storefront customization
Updates from review
1 parent fc4d48d commit bfed3f8

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed
Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
# How to add a storefront widget
22

3-
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.
47

58
Adding a storefront widget to your content type is a simple two-step process:
69

7-
8-
910
![How to add storefront widget](../images/how-to-add-storefront-widget.svg)
1011

11-
12-
1312
## Step 1: Create the JavaScript
1413

1514
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:
1615

1716
![Where to add storefront widget](../images/where-to-add-widget.png){:width="477px" height="auto"}
1817

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).
2019

2120
``` javascript
2221
define([
@@ -33,29 +32,24 @@ define([
3332

3433
## Step 2: Configure the widget initializer
3534

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:
3736

3837
``` xml
3938
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
4039
<type name="Magento\PageBuilder\Model\WidgetInitializerConfig">
4140
<arguments>
4241
<argument name="config" xsi:type="array">
43-
<item name="example_quote" xsi:type="array">
42+
<item name="example_quote" xsi:type="array">
4443
<!-- Name is the appearance name -->
4544
<item name="default" xsi:type="array">
4645
<!--required argument-->
47-
<item name="component" xsi:type="string">Example_PageBuilderQuote/js/content-type/example-quote/appearance/default/widget</item>
46+
<item name="component" xsi:type="string">Example_PageBuilderQuote/js/content-type/example-quote/appearance/default/widget</item>
47+
</item>
4848
</item>
49-
</item>
5049
</argument>
5150
</arguments>
5251
</type>
5352
</config>
5453
```
5554

56-
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

Comments
 (0)