Skip to content

Commit 06b9747

Browse files
committed
MC-5769: Complete content type tutorial
Completed draft of add templates topic and improved add configuration and overview
1 parent 9070839 commit 06b9747

10 files changed

+201
-49
lines changed

docs/create-basic-content-type/overview.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ Page Builder comes with 16 content types (controls) you can use to build your st
1111

1212
## Quote content type
1313

14-
Our Quote control will look like this when rendered in the Admin UI within a three-column grid:
14+
Here's an example of three Quote control instances rendered in three-columns on the Admin stage:
1515

1616
![QuoteTypeDisplay](../images/QuoteTypeDisplay.png)
1717

18-
And it will look like this when it's shown on a page in the storefront:
18+
And here are the same three quote controls rendered on a mock testimonial page in the storefront:
1919

2020
![StorefrontTestimonials](../images/StorefrontTestimonials.png)
2121

@@ -53,4 +53,4 @@ Before you get started, take a look at what you will be building. The block on t
5353
The file structure represents an overview of the conventions used for content types. Many of the conventions used are simply those defined for developing UI components. However, the conventions specific to Page Builder start within the directories called `content_type` or `content-type`. Page Builder instantiates a content type from the files defined within these directories. We discuss these conventions within each step of the process.
5454

5555
## Next
56-
[Step 1: Add configuration](step-1-add-configuration.md).
56+
[Step 1: Add configuration](step-1-add-configuration.md)

docs/create-basic-content-type/step-1-add-configuration.md

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ In our configuration, the `parents` element first prevents our content type from
103103

104104
The `<appearances>` element specifies one or more views for displaying your content type. For example, the Banner has four appearances you can choose from within its editor as shown here:
105105

106-
![BannerTemplateAppearanceExample](../images/BannerTemplateAppearanceExample.png)
106+
![banner-appearances](../images/banner-appearances.png)
107107

108-
Each of these appearances are defined as an `appearance` within the Banner configuration file (`app/code/Magento/PageBuilder/view/adminhtml/pagebuilder/content_type/banner.xml`):
108+
Each of these views is defined as an `appearance` within the Banner configuration file (`app/code/Magento/PageBuilder/view/adminhtml/pagebuilder/content_type/banner.xml`):
109109

110110
```xml
111111
<appearances>
@@ -118,34 +118,11 @@ Each of these appearances are defined as an `appearance` within the Banner confi
118118

119119
Going further, each `appearance` is defined by exactly two HTML templates, one to display a preview appearance in the Admin (`preview.html`) and the other to display the master appearance (`master.html`) on your storefront. We will discuss HTML templates more in [Step 2: Add templates](step-2-add-templates.md).
120120

121-
Our Quote only has one appearance, so we define it as the default:
122-
123-
```xml
124-
<appearances>
125-
<appearance name="default"
126-
default="true"
127-
preview_template="Vendor_Module/content-type/quote/default/preview"
128-
render_template="Vendor_Module/content-type/quote/default/master"
129-
reader="Magento_PageBuilder/js/master-format/read/configurable">
130-
<elements...>
131-
</appearance>
132-
</appearances>
133-
```
134-
135-
The `<appearance>` attributes are described as follows:
136-
137-
| Attribute | Description |
138-
| ------------------ | ------------------------------------------------------------ |
139-
| `name` | Name of the appearance so it can be extended as needed. |
140-
| `default` | Content types must specify one of the appearances as the default appearance. That means if you only have one appearance, it must be set as the default. |
141-
| `preview_template` | `preview.html` - the HTML template for rendering the preview appearance of a content type on the Admin stage during page development. |
142-
| `render_template` | `master.html` - the HTML template for rendering the storefront appearance of a content type for customers. |
143-
| `reader` | Reads data for the content type from the master format |
144-
145121
## The `elements` element
146122

147123
The purpose of `<elements>` as defined within an appearance is to map the data from the content type's edit form to the content type's master format so that the values entered in the form can be stored and rendered correctly on the Admin stage and storefront. We will describe the `elements` in [Step 4: Add form](step-4-add-form.md)
148124

149125
## Next
150126

151-
[Step 2: Add templates](step-2-add-templates.md).
127+
[Step 2: Add templates](step-2-add-templates.md)
128+

docs/create-basic-content-type/step-2-add-templates.md

Lines changed: 194 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,45 @@ The development of this tutorial is currently **IN PROGRESS**.
55

66
***
77

8-
Content type templates are the HTML files (fragments) that define how your content type *appears* on both the Admin stage and on a storefront page. In Page Builder this is called an `appearance`, as discussed in the previous configuration step.
8+
Content type templates are the HTML files (HTML fragments) that define how your content type *appears* on both the Admin stage and within your storefront. The combination of these templates (one `preview.html` and one `master.html`) creates an `appearance`. As discussed in the previous configuration step, you must have at least one `appearance` (two templates) defined for your content type. But like the Banner, you can define several appearances for users to choose from as shown here:
99

10-
Each `appearance` is defined by exactly two HTML template files: `preview.html` and `master.html`. For example, if you look at the template files for the Page Builder Banner, you see a set of these templates defined for each of Banner's four appearances:
10+
![banner-appearances](../images/banner-appearances.png)
1111

12-
![BannerBlockTemplateSets](../images/BannerBlockTemplateSets.png)
12+
## Template conventions
1313

14-
In contrast, the Block content type only has one `appearance`, so it defines it as the default with one set of master-preview template files.
14+
Conventions for adding content type templates are as follows.
1515

16-
## Conventions
16+
- Page Builder requires you to name your templates `preview.html` for the Admin template and `master.html` for the storefront template.
1717

18-
Conventions for adding content type templates are as follows:
18+
- Page Builder requires the name of an `appearance` to match the name of the directory containing the appearance templates. For example, `default` is the conventional name for content types with only one `appearance`. Therefore, the directory name should also be `default`.
1919

20-
- Page Builder requires at least one `appearance` (two HTML templates) for every content type: `preview.html` for the Admin stage, `master.html` for the storefront page. If your content type has only one appearance (like the Block), then it only needs these two templates.
20+
If you navigate to the Banner templates (`app/code/Magento/PageBuilder/view/adminhtml/web/template/content-type/banner`) you can see that the names of the template directories match the names of the four appearances defined in the `banner.xml` configuration file as shown here:
2121

22-
- Page Builder requires the names of your templates to be `preview` and `master`.
22+
```xml
23+
<appearances>
24+
<appearance name="collage-left"...>
25+
<appearance name="collage-centered"...>
26+
<appearance name="collage-right"...>
27+
<appearance name="poster" default="true" ...>
28+
</appearances>
29+
```
2330

24-
Content types cannot be rendered without these templates, so add them to your module (they can be blank initially) within the following directory structure (`view/adminhtml/web/template/content-type/<content-type-name>/default/`):
31+
![BannerBlockTemplateSets](../images/BannerBlockTemplateSets.png)
2532

26-
![Create config file](../images/step2-add-templates.png)
2733

28-
As mentioned, these files can be empty initially; they just need to exist in their proper location within your module.
34+
## Template Configuration
2935

30-
## Configuration
36+
The Quote example defines only one `appearance`. Therefore, by convention, set the names of the Quote `appearance` and the template directory to `default` as shown in the code and directory structure that follows:
3137

32-
In your configuration file, you need to reference your templates within the `<appearance>` element as follows:
38+
```xml
39+
<appearances>
40+
<appearance name="default"
41+
...
42+
```
43+
44+
![Create config file](../images/step2-add-templates.png)
45+
46+
These files can be blank initially; they just need to exist in their proper location for now so we can reference them in the `appearance` element of our `quote.xml` configuration file as shown here:
3347

3448
```xml
3549
<appearances>
@@ -43,11 +57,174 @@ In your configuration file, you need to reference your templates within the `<ap
4357
</appearances>
4458
```
4559

46-
| Attribute | Description |
47-
| ---------------- | ------------------------------------------------------------ |
60+
The following table describes each `appearance` attribute in our example.
61+
62+
| Attribute | Description |
63+
| ------------------ | ------------------------------------------------------------ |
64+
| `name` | As noted by convention, the name of the appearance and the name of the directory for the appearance templates *must* match. |
65+
| `default` | Every content type must have a default appearance. If you only define one appearance for your content type, you must set the default to `true`. |
4866
| `preview_template` | References the`preview.html` template for rendering the preview appearance of your content type on the stage within the Admin UI. |
49-
| `render_template` | References the `master.html` template for rendering the appearance of your content type on the storefront for customers to see. |
67+
| `render_template` | References the `master.html` template for rendering the appearance of your content type on the storefront for customers to see. |
68+
| `reader` | Reads data for the content type from the master format. |
69+
70+
## Quote `preview.html`
71+
72+
The `preview.html` template defined for the Quote appearance, is shown here in full followed by descriptions to help you understand the basics of this template.
73+
74+
```html
75+
<!-- preview.html -->
76+
<div attr="data.main.attributes"
77+
ko-style="data.main.style"
78+
class="pagebuilder-content-type"
79+
css="data.main.css"
80+
event="{ mouseover: onMouseOver, mouseout: onMouseOut }, mouseoverBubble: false">
81+
<render args="getOptions().template" />
82+
<blockquote attr="data.quote.attributes"
83+
ko-style="data.quote.style"
84+
css="data.quote.css"
85+
data-bind="liveEdit: { field: 'quote_text', placeholder: $t('Enter Quote') }">
86+
</blockquote>
87+
<div class="quote-author"
88+
attr="data.author.attributes"
89+
ko-style="data.author.style"
90+
css="data.author.css"
91+
data-bind="liveEdit: { field: 'quote_author', placeholder: $t('Enter Author') }">
92+
</div>
93+
<div class="quote-title"
94+
attr="data.author_title.attributes"
95+
ko-style="data.author_title.style"
96+
css="data.author_title.css"
97+
data-bind="liveEdit: { field: 'quote_author_desc', placeholder: $t('Enter Description') }">
98+
</div>
99+
</div>
100+
```
101+
102+
### attr
103+
104+
The `attr` attribute allows binding of data from the content type form (UI component) to the html elements in the template. Without defining the `attr` for an HTML element in your template, bindings like `ko-style`, `css`, `html`, and `events` won't work.
105+
106+
The value for `attr` is derived from the `element` name in the configuration file followed by `attributes`. For example, the `attr` value used to bind data for the `blockquote` on line 8 of the Quote `preview.html` is `attr="data.quote.attributes"`. This corresponds to the `element` named `quote` in the `quote.xml` configuration file, as shown here:
107+
108+
```xml
109+
<!-- quote.xml -->
110+
<element name="quote">
111+
<html name="quote_text" converter="Magento_PageBuilder/js/converter/html/tag-escaper"/>
112+
<css name="quote_css"/>
113+
</element>
114+
```
115+
116+
The nodes declared within an `element` define the bindings that can be applied to your templates.
117+
118+
### ko-style
119+
120+
The `ko-style` attribute applies the `<style>` attributes from the form to a template element. For example, the `main` element for the Quote configuration defines several style bindings as shown here:
121+
122+
```xml
123+
<!-- quote.xml -->
124+
<element name="main">
125+
<style name="text_align" source="text_align"/>
126+
<style name="border" source="border_style" converter="Magento_PageBuilder/js/converter/style/border-style"/>
127+
<style name="border_color" source="border_color"/>
128+
<style name="background_color" source="background_color"/>
129+
<style name="border_width" source="border_width" converter="Magento_PageBuilder/js/converter/style/border-width"/>
130+
<style name="border_radius" source="border_radius" converter="Magento_PageBuilder/js/converter/style/remove-px"/>
131+
<style name="margins" storage_key="margins_and_padding" reader="Magento_PageBuilder/js/property/margins" converter="Magento_PageBuilder/js/converter/style/margins"/>
132+
<style name="padding" storage_key="margins_and_padding" reader="Magento_PageBuilder/js/property/paddings" converter="Magento_PageBuilder/js/converter/style/paddings"/>
133+
...
134+
</element>
135+
```
136+
137+
As we discuss more in [Step 4: Add form](step-4-add-form.md), the `element` styles define bindings to fields in our form. In turn, these form fields provide user-entered data or default values that we apply to the HTML elements in our templates using the `k0-style` attribute.
138+
139+
The following snippet shows the `ko-style` (Knockout binding) that applies the styles defined in the main `element` to the `div` node of the Quote's preview template:
140+
141+
```html
142+
<!-- preview.html -->
143+
<div attr="data.main.attributes" ko-style="data.main.style"...>
144+
<!-- other template elements -->
145+
</div>
146+
```
147+
148+
The `ko-style` value is derived from the configuration `element` name (`main`) and the attribute to be bound (`style`) to give us `data.main.style`.
149+
150+
### css
151+
152+
The `css` attribute applies CSS classes entered by users on the form to a template element. More on this when we discuss forms in [Step 4: Add form](step-4-add-form.md).
153+
154+
### class
155+
156+
Just as with any other html template, you can add your own classes to your template elements. Defining those classes for your content type is discussed in [Step 5: Add styles](step-5-add-styles.md).
157+
158+
### liveEdit
159+
160+
The `liveEdit` binding enables end users to enter HTML content directly on the Admin stage. The basic usage from the Quote control includes specifying the form field it binds to and adding placeholder text as follows:
161+
162+
```html
163+
<!-- preview.html -->
164+
<blockquote attr="data.quote.attributes"
165+
data-bind="liveEdit: { field: 'quote_text', placeholder: $t('Enter Quote') }">
166+
</blockquote>
167+
```
168+
169+
### event
170+
171+
To be completed.
172+
173+
## Quote `master.html`
174+
175+
The `master.html` template defined for the Quote appearance is shown here in full. The same attributes and descriptions from the preview template apply to this template as well, with one addition, the `html` attribute.
176+
177+
```html
178+
<!--master.html-->
179+
<div attr="data.main.attributes">
180+
<blockquote attr="data.quote.attributes"
181+
ko-style="data.quote.style"
182+
css="data.quote.css"
183+
html="data.quote.html">
184+
</blockquote>
185+
<div class="quote-author"
186+
attr="data.author.attributes"
187+
ko-style="data.author.style"
188+
css="data.author.css"
189+
html="data.author.html">
190+
</div>
191+
<div class="quote-title"
192+
attr="data.author_title.attributes"
193+
ko-style="data.author_title.style"
194+
css="data.author_title.css"
195+
html="data.author_title.html">
196+
</div>
197+
</div>
198+
```
199+
200+
### html
201+
202+
The `html` attribute applies the actual user-entered HTML to the template element. In our Quote example, the end-user enters their quote text either from the Admin stage using `liveEdit`, which is bound to the `quote_text` field, or from the form.
203+
204+
```html
205+
<!--preview.html-->
206+
<blockquote data-bind="liveEdit: { field: 'quote_text', placeholder: $t('Enter Quote') }">
207+
</blockquote>
208+
```
209+
210+
From `liveEdit`, we see that the content of `blockquote` is bound to the `quote_text` field that stores the html.
211+
212+
The master template uses the `html` attribute to retrieve the HTML content and display it in the `blockquote` element:
213+
214+
```html
215+
<!--master.html-->
216+
<blockquote html="data.quote.html"></blockquote>
217+
```
218+
219+
The `html` value is derived from the configuration `element` name (`quote`) and the attribute to be bound (`html`) to give us `data.quote.html`.
220+
221+
```xml
222+
<element name="quote">
223+
<html name="quote_text" converter="Magento_PageBuilder/js/converter/html/tag-escaper"/>
224+
...
225+
```
50226

227+
## Next
51228

229+
[Step 3: Add components](step-3-add-components.md)
52230

53-
The remainder of this topic is in progress.

docs/create-basic-content-type/step-3-add-components.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ In your configuration file, reference your JavaScript component (`preview.js`) a
2828
| `preview_component` | `preview.js` - Optional JavaScript file that provides preview-specific rendering logic within the Admin UI. If your content type does not require any specific user-interactivity or other behavior in the Admin, you can simply omit this attribute from the the `<type>`. Page Builder will use `Magento_PageBuilder/js/content-type/preview` by default. |
2929
| `master_component` | `master.js` - Optional JavaScript file that provides master format rendering logic generic for all appearances of your content type when rendered on the storefront. Same as with the `preview_component`, if your content type does not require any specific user-interactivity or other behavior when it's displayed in the storefront, you can simply omit this attribute from the the `<type>`. Page Builder will use `Magento_PageBuilder/js/content-type/master` by default (as shown in the example). |
3030

31-
{:style="table-layout:auto"}
32-
3331
## Location
3432

3533
Add them to your module here (`view/adminhtml/web/js/content-type/<content-type-name>/`):
6.11 KB
Loading
-7.83 KB
Loading
236 KB
Binary file not shown.

docs/images/QuoteTypeDisplay.png

-1.04 KB
Loading
9.79 KB
Loading

docs/images/banner-appearances.png

21.8 KB
Loading

0 commit comments

Comments
 (0)