|
1 | 1 | --- |
2 | 2 | name: b2c-page-designer |
3 | | -description: Create Page Designer pages and components in B2C Commerce. Use when building visual merchandising tools, content slots, or experience API integrations. Covers page types, component types, regions, and attribute definitions. |
| 3 | +description: Create Page Designer pages and components in B2C Commerce. Use when building visual merchandising tools, content slots, or experience API integrations. Covers page types, component types, regions, attribute definitions, component type ID and subfolders, enum and custom/color attribute pitfalls, and troubleshooting when a component does not appear in the editor. |
4 | 4 | --- |
5 | 5 |
|
6 | 6 | # Page Designer Skill |
@@ -37,7 +37,9 @@ Page Designer files are in the cartridge's `experience` directory: |
37 | 37 | banner.isml # Component template |
38 | 38 | ``` |
39 | 39 |
|
40 | | -**Naming:** The `.json` and `.js` files must have matching names. |
| 40 | +**Naming:** The `.json` and `.js` files must have matching names. Use only **alphanumeric** or **underscore** in file names and in any subdirectory names under `experience/pages` or `experience/components`. |
| 41 | + |
| 42 | +**Component types in subfolders:** You can put component meta and script in a subdirectory (e.g. `experience/components/assets/`). The **component type ID** is then the path with dots: `assets.hero_image_block`. The template path under `templates/default/` must mirror that path (e.g. `templates/default/experience/components/assets/hero_image_block.isml`), and the script must call `Template('experience/components/assets/hero_image_block')` so the path matches. Stored ID is `component.{component_type_id}`; total length must not exceed 256 characters. |
41 | 43 |
|
42 | 44 | ## Page Types |
43 | 45 |
|
@@ -119,6 +121,7 @@ module.exports.render = function (context) { |
119 | 121 | "name": "Banner", |
120 | 122 | "description": "Promotional banner with image and CTA", |
121 | 123 | "group": "content", |
| 124 | + "region_definitions": [], |
122 | 125 | "attribute_definition_groups": [ |
123 | 126 | { |
124 | 127 | "id": "image", |
@@ -188,6 +191,8 @@ module.exports.render = function (context) { |
188 | 191 | } |
189 | 192 | ``` |
190 | 193 |
|
| 194 | +**Component meta:** Always include `region_definitions`. Use `[]` when the component has no nested regions (no slots for other components). |
| 195 | + |
191 | 196 | ### Component Script (components/banner.js) |
192 | 197 |
|
193 | 198 | ```javascript |
@@ -215,6 +220,19 @@ module.exports.render = function (context) { |
215 | 220 | }; |
216 | 221 | ``` |
217 | 222 |
|
| 223 | +**Template path:** The path passed to `Template(...)` must match the template path under `templates/default/`. If the component lives in a subfolder (e.g. `experience/components/assets/hero_image_block`), use `Template('experience/components/assets/hero_image_block')` and place the ISML at `templates/default/experience/components/assets/hero_image_block.isml`. |
| 224 | + |
| 225 | +**Handling colors (string or color picker object):** If an attribute can be a hex string or a color picker object `{ color: "#hex" }`, use a small helper so the script works with both: |
| 226 | + |
| 227 | +```javascript |
| 228 | +function getColor(colorAttr) { |
| 229 | + if (!colorAttr) return ''; |
| 230 | + if (typeof colorAttr === 'string' && colorAttr.trim()) return colorAttr.trim(); |
| 231 | + if (colorAttr.color) return colorAttr.color; |
| 232 | + return ''; |
| 233 | +} |
| 234 | +``` |
| 235 | + |
218 | 236 | ### Component Template (templates/experience/components/banner.isml) |
219 | 237 |
|
220 | 238 | ```html |
@@ -260,7 +278,13 @@ module.exports.render = function (context) { |
260 | 278 | | `category` | Category selector | Category object | |
261 | 279 | | `product` | Product selector | Product object | |
262 | 280 | | `page` | Page selector | Page object | |
263 | | -| `custom` | JSON object | Object | |
| 281 | +| `custom` | JSON object or custom editor | Object (or editor-specific) | |
| 282 | + |
| 283 | +**Enum — critical for component visibility:** Use a **string array** for `values`: `"values": ["left", "center", "right"]`. Do **not** use objects like `{ "value": "x", "display_value": "X" }`; that format can cause the component type to be rejected and **not appear** in the Page Designer component list. |
| 284 | + |
| 285 | +**Custom and colors:** `type: "custom"` with e.g. `editor_definition.type: "styling.colorPicker"` requires a cartridge that provides that editor on the **Business Manager** site cartridge path. If the component does not show up in the editor, use `type: "string"` for color attributes (merchant types a hex). In the script, support both: accept a string or an object like `{ color: "#hex" }` (e.g. a small `getColor(attr)` helper that returns the string). |
| 286 | + |
| 287 | +**default_value:** Used for storefront rendering only; it is **not** shown as preselected in the Page Designer visual editor. |
264 | 288 |
|
265 | 289 | ## Region Definitions |
266 | 290 |
|
@@ -337,14 +361,25 @@ Organize components in the editor sidebar: |
337 | 361 |
|
338 | 362 | Common groups: `content`, `products`, `navigation`, `layout`, `media` |
339 | 363 |
|
| 364 | +## If the component does not appear in Page Designer |
| 365 | + |
| 366 | +1. **Enums:** Ensure all `enum` attributes use `"values": ["a", "b"]` (string array), not objects with `value`/`display_value`. |
| 367 | +2. **Custom editors:** Replace `type: "custom"` (e.g. color picker) with `type: "string"` for the problematic attributes and redeploy; if the component then appears, the issue is likely the custom editor or BM cartridge path. |
| 368 | +3. **Naming:** File and subdirectory names only alphanumeric or underscore. |
| 369 | +4. **region_definitions:** Component meta must include `region_definitions` (use `[]` if no nested regions). |
| 370 | +5. **Template path:** Script `Template('...')` path must match the template path under `templates/default/` (including subfolders like `experience/components/assets/...`). |
| 371 | +6. **Logs:** In Business Manager, **Administration > Site Development > Development Setup**, check error logs when opening Page Designer for script or meta errors related to your component type ID. |
| 372 | +7. **Code version:** Deploy the cartridge to the correct code version; in non-production, meta can be cached for a few seconds—try a code version switch or short wait. |
| 373 | + |
340 | 374 | ## Best Practices |
341 | 375 |
|
342 | 376 | 1. **Use `dw.util.Template`** for rendering (NOT `dw.template.ISML`) |
343 | 377 | 2. **Keep components self-contained** - avoid cross-component dependencies |
344 | | -3. **Provide default values** for optional attributes |
| 378 | +3. **Provide default values** for optional attributes (they apply to rendering; not shown as preselected in the editor) |
345 | 379 | 4. **Group related attributes** in `attribute_definition_groups` |
346 | 380 | 5. **Use meaningful IDs** - they're used programmatically |
347 | | -6. **Don't change type IDs** after merchants create content |
| 381 | +6. **Don't change type IDs or attribute types** after merchants create content (creates inconsistency with stored data); add a new component type and deprecate the old one if needed |
| 382 | +7. **Prefer string arrays for enums** and **string for colors** unless you control the BM cartridge path and custom editors |
348 | 383 |
|
349 | 384 | ## Detailed Reference |
350 | 385 |
|
|
0 commit comments