Lab - Widgets and Page Builder
Lab - Widgets and Page Builder
Lab - Widgets and Page Builder
Plan: Stencil Developer
Lesson 17 of 22 · 45 minIn this lab you will
Prerequisites
https://api.bigcommerce.com/stores/{{store_hash}}/v3/content/widget-templatesWe will use information from this response to build out the POST request that will create our widget - starting with copying the ‘Divider’ widget as shown below.
{ "uuid": "fdf5b5fd-5599-4eec-beaa-b4a9fbc1e522", "name": "Divider", "schema": [ { "type": "tab", "label": "Design", "sections": [ { "settings": [ { "type": "color", "label": "Line color", "id": "color", "default": "rgba(180, 186, 209, 1)" }, { "type": "select", "label": "Line style", "id": "style", "default": "solid", "typeMeta": { "selectOptions": [ { "label": "Solid", "value": "solid" }, { "label": "Dashed", "value": "dashed" }, { "label": "Dotted", "value": "dotted" } ] } }, { "type": "range", "label": "Line width", "id": "width", "default": 100, "typeMeta": { "rangeValues": { "min": 1, "max": 100, "step": 1, "unit": "%" } } }, { "type": "range", "label": "Line thickness", "id": "thickness", "default": 1, "typeMeta": { "rangeValues": { "min": 1, "max": 10, "step": 1, "unit": "px" } } }, { "type": "alignment", "label": "Alignment", "id": "alignment", "default": { "horizontal": "center", "vertical": "middle" }, "typeMeta": { "display": "both" } } ] } ] } ], "template": "<style>\n .sd-divider-wrapper-{{_.id}} {\n display: flex;\n height: 20px;\n {{#if alignment.vertical '===' 'middle'}}\n align-items: center;\n {{else if alignment.vertical '===' 'top'}}\n align-items: flex-start;\n {{else if alignment.vertical '===' 'bottom'}}\n align-items: flex-end;\n {{/if}}\n {{#if alignment.horizontal '===' 'center'}}\n justify-content: center;\n text-align: center;\n {{else if alignment.horizontal '===' 'left'}}\n justify-content: flex-start;\n text-align: left;\n {{else if alignment.horizontal '===' 'right'}}\n justify-content: flex-end;\n text-align: right;\n {{/if}}\n }\n\n .sd-divider-{{_.id}} {\n height: 0;\n border-top: {{thickness}}px;\n border-color: {{color}};\n border-style: {{style}};\n width: {{width}}%;\n margin: 0;\n }\n</style>\n\n<div class=\"sd-divider-wrapper-{{_.id}}\">\n <hr class=\"sd-divider-{{_.id}}\"/>\n</div>\n", "date_created": "2019-07-31T01:30:01.806Z", "date_modified": "2020-04-07T17:40:32.935Z", "kind": "sd-divider", "storefront_api_query": "", "icon_name": "sd-divider", "template_engine": "handlebars_v3", "client_rerender": false, "site_id": null }


{ "name": "Divider Spacer Combo", "schema": [ { "type": "tab", "label": "Design", "sections": [ { "settings": [ { "type": "color", "label": "Line color", "id": "color", "default": "rgba(180, 186, 209, 1)" }, { "type": "select", "label": "Line style", "id": "style", "default": "solid", "typeMeta": { "selectOptions": [ { "label": "Solid", "value": "solid" }, { "label": "Dashed", "value": "dashed" }, { "label": "Dotted", "value": "dotted" } ] } }, { "type": "range", "label": "Line width", "id": "width", "default": 100, "typeMeta": { "rangeValues": { "min": 1, "max": 100, "step": 1, "unit": "%" } } }, { "type": "range", "label": "Line thickness", "id": "thickness", "default": 1, "typeMeta": { "rangeValues": { "min": 1, "max": 10, "step": 1, "unit": "px" } } }, { "type": "alignment", "label": "Alignment", "id": "alignment", "default": { "horizontal": "center", "vertical": "middle" }, "typeMeta": { "display": "both" } } ] } ] } ], "template": "<style>\n .sd-divider-wrapper-{{_.id}} {\n display: flex;\n height: 20px;\n {{#if alignment.vertical '===' 'middle'}}\n align-items: center;\n {{else if alignment.vertical '===' 'top'}}\n align-items: flex-start;\n {{else if alignment.vertical '===' 'bottom'}}\n align-items: flex-end;\n {{/if}}\n {{#if alignment.horizontal '===' 'center'}}\n justify-content: center;\n text-align: center;\n {{else if alignment.horizontal '===' 'left'}}\n justify-content: flex-start;\n text-align: left;\n {{else if alignment.horizontal '===' 'right'}}\n justify-content: flex-end;\n text-align: right;\n {{/if}}\n }\n\n .sd-divider-{{_.id}} {\n height: 0;\n border-top: {{thickness}}px;\n border-color: {{color}};\n border-style: {{style}};\n width: {{width}}%;\n margin: 0;\n }\n</style>\n\n<div class=\"sd-divider-wrapper-{{_.id}}\">\n <hr class=\"sd-divider-{{_.id}}\"/>\n</div>\n", "date_created": "2019-07-31T01:30:01.806Z", "date_modified": "2020-04-07T17:40:32.935Z", "kind": "sd-divider", "storefront_api_query": "", "icon_name": "sd-divider", "template_engine": "handlebars_v3", "client_rerender": false, "site_id": null }
Copy the ‘spacer’ schema

Copy the section from the Spacer schema as shown.
{ "type": "range", "id": "spaceSize", "default": 50, "typeMeta": { "rangeValues": { "min": 0, "max": 200, "step": 1, "unit": "px" } } }
"schema": [ { "type": "tab", "label": "Design", "sections": [ { "settings": [ { "type": "color", "label": "Line color", "id": "color", "default": "rgba(180, 186, 209, 1)" }, { "type": "select", "label": "Line style", "id": "style", "default": "solid", "typeMeta": { "selectOptions": [ { "label": "Solid", "value": "solid" }, { "label": "Dashed", "value": "dashed" }, { "label": "Dotted", "value": "dotted" } ] } }, { "type": "range", "label": "Line width", "id": "width", "default": 100, "typeMeta": { "rangeValues": { "min": 1, "max": 100, "step": 1, "unit": "%" } } }, { "type": "range", "label": "Line thickness", "id": "thickness", "default": 1, "typeMeta": { "rangeValues": { "min": 1, "max": 10, "step": 1, "unit": "px" } } }, { "type": "alignment", "label": "Alignment", "id": "alignment", "default": { "horizontal": "center", "vertical": "middle" }, "typeMeta": { "display": "both" } }, { "type": "range", "label": "Space Size", "id": "spaceSize", "default": 50, "typeMeta": { "rangeValues": { "min": 0, "max": 200, "step": 1, "unit": "px" } } } ] } } ]
Modify the divider template

a. Copy between the strings, starting at ”<” and ending at “n”.
"template": "<style>\n .sd-spacer-{{_.id}} {\n height: {{spaceSize}}px;\n }\n</style>\n\n<div class=\"sd-spacer-{{_.id}}\">\n </div>\n <style>\n .sd-divider-wrapper-{{_.id}} {\n display: flex;\n height: 20px;\n {{#if alignment.vertical '===' 'middle'}}\n align-items: center;\n {{else if alignment.vertical '===' 'top'}}\n align-items: flex-start;\n {{else if alignment.vertical '===' 'bottom'}}\n align-items: flex-end;\n {{/if}}\n {{#if alignment.horizontal '===' 'center'}}\n justify-content: center;\n text-align: center;\n {{else if alignment.horizontal '===' 'left'}}\n justify-content: flex-start;\n text-align: left;\n {{else if alignment.horizontal '===' 'right'}}\n justify-content: flex-end;\n text-align: right;\n {{/if}}\n }\n\n <hr class=\"sd-divider-{{_.id}}\"/>\n</div>\n"
https://api.bigcommerce.com/stores/{{store_hash}}/v3/content/widget-templates
{ "name": "Divider Spacer Combo", "schema": [ { "type": "tab", "label": "Design", "sections": [ { "settings": [ { "type": "color", "label": "Line color", "id": "color", "default": "rgba(180, 186, 209, 1)" }, { "type": "select", "label": "Line style", "id": "style", "default": "solid", "typeMeta": { "selectOptions": [ { "label": "Solid", "value": "solid" }, { "label": "Dashed", "value": "dashed" }, { "label": "Dotted", "value": "dotted" } ] } }, { "type": "range", "label": "Line width", "id": "width", "default": 100, "typeMeta": { "rangeValues": { "min": 1, "max": 100, "step": 1, "unit": "%" } } }, { "type": "range", "label": "Line thickness", "id": "thickness", "default": 1, "typeMeta": { "rangeValues": { "min": 1, "max": 10, "step": 1, "unit": "px" } } }, { "type": "alignment", "label": "Alignment", "id": "alignment", "default": { "horizontal": "center", "vertical": "middle" }, "typeMeta": { "display": "both" } }, { "type": "range", "label": "Space Size", "id": "spaceSize", "default": 50, "typeMeta": { "rangeValues": { "min": 0, "max": 200, "step": 1, "unit": "px" } } } ] } ] } ], "template": "<style>\n .sd-spacer-{{_.id}} {\n height: {{spaceSize}}px;\n }\n</style>\n\n<div class=\"sd-spacer-{{_.id}}\">\n</div>\n <style>\n .sd-divider-wrapper-{{_.id}} {\n display: flex;\n height: 20px;\n {{#if alignment.vertical '===' 'middle'}}\n align-items: center;\n {{else if alignment.vertical '===' 'top'}}\n align-items: flex-start;\n {{else if alignment.vertical '===' 'bottom'}}\n align-items: flex-end;\n {{/if}}\n {{#if alignment.horizontal '===' 'center'}}\n justify-content: center;\n text-align: center;\n {{else if alignment.horizontal '===' 'left'}}\n justify-content: flex-start;\n text-align: left;\n {{else if alignment.horizontal '===' 'right'}}\n justify-content: flex-end;\n text-align: right;\n {{/if}}\n }\n\n .sd-divider-{{_.id}} {\n height: 0;\n border-top: {{thickness}}px;\n border-color: {{color}};\n border-style: {{style}};\n width: {{width}}%;\n margin: 0;\n }\n</style>\n\n<div class=\"sd-divider-wrapper-{{_.id}}\">\n <hr class=\"sd-divider-{{_.id}}\"/>\n</div>\n" }



If you have successfully created the widget, it should appear, be available, and work correctly through the Page Builder. If it’s not appearing as expected or you are not able to open Page Builder, please verify that it has been correctly configured.