|
1 |
| -# Step 1: Add a configuration |
| 1 | +# Step 1: Add configuration |
| 2 | + |
| 3 | +Creating a configuration file is the first step to creating a new content type. Through the configuration file, you can specify things like the label, location, and icon of your content type within the Page Builder panel menu. You can specify where your content type can be dropped on the stage, and reference the many other files you will use to control the appearance and behavior your content type. |
| 4 | + |
| 5 | +## Create the configuration file |
| 6 | + |
| 7 | +1. Create a new XML file in the following directory structure of your module: `view/adminhtml/pagebuilder/content_type/my-content-type.xml`. |
| 8 | + |
| 9 | +2. Copy the contents of this example into your `my-content-type.xml` file: |
| 10 | + ``` xml |
| 11 | + <?xml version="1.0"?> |
| 12 | + <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_PageBuilder:etc/content_type.xsd"> |
| 13 | + <type name="my-content-type" |
| 14 | + label="My Content Type" |
| 15 | + group="layout" |
| 16 | + component="Magento_PageBuilder/js/content-type-collection" |
| 17 | + preview_component="Magento_PageBuilder/js/content-type/preview" |
| 18 | + master_component="Magento_PageBuilder/js/content-type/master" |
| 19 | + form="" |
| 20 | + icon="" |
| 21 | + sortOrder="-1" |
| 22 | + is_hideable="true" |
| 23 | + translate="label"> |
| 24 | + <appearances> |
| 25 | + <appearance name="default" |
| 26 | + default="true" |
| 27 | + preview_template="Vendor_Module/content-type/my-content-type/default/preview" |
| 28 | + render_template="Vendor_Module/content-type/my-content-type/default/master" |
| 29 | + reader="Magento_PageBuilder/js/master-format/read/configurable"> |
| 30 | + <elements> |
| 31 | + <element name="main"> |
| 32 | + <attribute name="name" source="data-role"/> |
| 33 | + <attribute name="appearance" source="data-appearance"/> |
| 34 | + </element> |
| 35 | + </elements> |
| 36 | + </appearance> |
| 37 | + </appearances> |
| 38 | + </type> |
| 39 | + </config> |
| 40 | + ``` |
| 41 | + |
| 42 | +3. Create the required `preview_template` and `render_template` as specified in the configuration file. |
| 43 | + |
| 44 | + Before seeing the results of our configuration in the Page Builder panel menu, we need to create the two templates specified in the <appearance> element of the configuration file: |
| 45 | + * preview.html - to display our content type within the Admin UI. |
| 46 | + * master.html - to display our content type within the CMS page on the storefront. |
| 47 | + |
| 48 | + Both templates are required. So for now, just create the files within the following directory structure, `view/adminhtml/web/template/content_type/my-content-type/default/`, using the example content that follows. We will discuss them in detail later: |
| 49 | + |
| 50 | + ```html |
| 51 | + <!--preview.html--> |
| 52 | + <div class="pagebuilder-content-type" event="{ mouseover: onMouseOver, mouseout: onMouseOut }, mouseoverBubble: false"> |
| 53 | + <render args="getOptions().template" /> |
| 54 | + <div attr="data.main.attributes" css="data.main.css" ko-style="data.main.style"> |
| 55 | + <div style="width: 100%; height: 100px; background-color: #f1f1f1; padding: 20px;">Admin template</div> |
| 56 | + </div> |
| 57 | + </div> |
| 58 | + ``` |
| 59 | + |
| 60 | + ```html |
| 61 | + <!--master.html--> |
| 62 | + <div class="pagebuilder-content-type" event="{ mouseover: onMouseOver, mouseout: onMouseOut }, mouseoverBubble: false"> |
| 63 | + <render args="getOptions().template" /> |
| 64 | + <div attr="data.main.attributes" css="data.main.css" ko-style="data.main.style"> |
| 65 | + <div style="width: 100%; height: 100px; background-color: #f1f1f1; padding: 20px;">Admin template</div> |
| 66 | + </div> |
| 67 | + </div> |
| 68 | + ``` |
| 69 | + |
| 70 | +4. Flush your config cache `bin/magento cache:flush config` and view Page Builder from the Home Page editor (as a convenience for storefront viewing later). The Page Builder panel menu should show your content type at the top of the layout group: |
| 71 | + |
| 72 | +  |
| 73 | + |
0 commit comments