Building a Purple Experience
...
Components
Widget Component

Example for widget definition

8min

Ideally, prepare a list of third-party HTML resources, you want to set up as widgets, including stylesheets and scripts.

In Builder, navigate to default/storefront/assets. Via 'Actions', create a new file

Click on 'Create File'


Create a "generic-widget.json", and once its created add the initial array to the file, with adding "[]"

Click on 'Create generic-widget.json'


Close and re-open the Editor. It now should look like this:

Click on the plus symbol


Next to 'name' type the Widget Library name. You may use this to structure multiple widgets of different distributors. We use 'demo' as an example:

Next to 'name' type the Widget Library name


To now add widgets to the library. Demo Library, click on the Properties icon

Demo Library, click on the Properties icon


10. Name your Widget and confirm via clicking the Plus icon.

type the name of the first widget then click on the Plus icon


11. Next to 'html' insert or type the HTML of the widget. We used "<div id="demo-widget-1" class=“demo-widget">" as an example

Next to 'html' insert or type the HTML of the widget.


12. Below 'resources' click on the plus icon.

Below 'resources' click on the plus icon


13. Click on the properties icon

Click on the properties icon


14. Check the boxes next to all your needed resources. When done, click on the properties icon again.

Check the boxes next to all your needed resources.


15. Next to 'URL' type the URL of the resource. We used "https://demo.min.js" as an example

Next to 'URL' type the URL of the resource.


16. Next to 'placement', choose whether to put your widget in the head or the body

choose whether to put your widget in the head or the body


17. Next to position, select the position of the resource

select the position of the resource


18. Next to 'properties', click on the properties icons

click on the properties icons


We added here only an empty async.

Add the script of your property and click on the plus symbol


20. On the bottom of the Resources section, click on the plus symbol to add the Global resources.

Repeat steps from 13- 17 to create global resources.

click on the plus symbol


21. You can add another widget library by clicking on the plus symbol

add another widget library by clicking on the plus symbol


22. After configuring your first generic widget, you need to tell the application about it's existence. To do that, open your urls.json, which is located in same folder. You can add the GenericWidget property simply by clicking the Property-Button on the top right of the urls.json pane.

Document image


23. Now add the path accordingly.

Document image


Example

HTML


This is a widget from 'weekli' to be integrated. It contains an html div tag with a script. The script should be loaded after the html div tag.

The configuration within the "generic-widget.json" should resemble:

Document image




Updated 18 Dec 2024
Did this page help you?