A Page Designer component or page type is a pair of files with the same name: a meta JSON that declares its attributes and regions, and a render script. Intellij SFCC connects the two. The render script's context is typed, context.content gets a member for every attribute of the meta JSON, and the meta JSON completes groups, component types and editor types from your cartridges
group and type_id complete from your cartridges and Cmd+Click on a type ID opens the component's JSON or script. The render script types context.content from the attributes of its meta JSONBefore you start
| Needs | Why |
|---|---|
Files in cartridge/experience | The plugin recognizes Page Designer files by folder: experience/components, experience/pages, experience/editors and experience/aspects |
| A linked cartridge | Render scripts are typed only in linked cartridges, see Cartridges & Modules |
| A valid license or trial | Completion and Cmd+Click in the meta JSON are part of the paid features, see Purchase & License |
Typed render scripts
The plugin types the parameters of the function named render in a script under experience/components or experience/pages, for example module.exports.render = function (context, modelIn) { ... }
| Parameter | In a component script | In a page script |
|---|---|---|
First, context | dw.experience.ComponentScriptContext | dw.experience.PageScriptContext |
Second, modelIn | dw.util.Map | dw.util.Map |
So context.component, context.componentRenderSettings and the other members of the script context complete without a JSDoc comment
context.content
context.content gets one member for each attribute in the attribute_definitions of the meta JSON next to the script, heroBanner.json for heroBanner.js. The member's type comes from the attribute's type
{
"name": "Hero Banner",
"group": "commerce_assets",
"region_definitions": [],
"attribute_definition_groups": [
{
"id": "content",
"name": "Content",
"attribute_definitions": [
{ "id": "image", "type": "image" },
{ "id": "heading", "type": "string" },
{ "id": "categoryLink", "type": "category" }
]
}
]
}'use strict';
var Template = require('dw/util/Template');
var HashMap = require('dw/util/HashMap');
module.exports.render = function (context, modelIn) {
var model = modelIn || new HashMap();
model.heading = context.content.heading; // string
model.image = context.content.image; // dw.experience.image.Image
model.category = context.content.categoryLink; // dw.catalog.Category
return new Template('experience/components/commerce_assets/heroBanner').render(model).text;
};Attribute type | Member type |
|---|---|
string | string |
boolean | boolean |
integer | int |
category | dw.catalog.Category |
cms_record | dw.experience.CMSRecord |
custom | dw.util.Map |
file | dw.content.MediaFile |
image | dw.experience.image.Image |
page | dw.experience.Page |
product | dw.catalog.Product and dw.catalog.Variant |
Any other type, such as text, markup, enum or url | string |
A page script reads the attributes of its page type JSON the same way. context.getContent() keeps the dw.util.Map type of the typings, only the content property is typed this way
Complete the meta JSON
Inside a meta JSON, these values complete from the Page Designer files of your cartridges. Press Ctrl+Space in the empty string to open the list
| Value | Completes | Each item shows |
|---|---|---|
group | Every group declared in a Page Designer JSON file | The group name |
type_id, for example in component_type_inclusions | Component type IDs from experience/components, as a dotted path such as commerce_assets.heroBanner | The JSON file icon, the word components and the cartridge on the right |
type inside editor_definition | Custom editor type IDs from experience/editors | The JSON file icon, the word editors and the cartridge on the right |
scripts and styles arrays | JavaScript and CSS files from the static folders of your cartridges, as a path below the locale folder such as /js/editors/colorPicker.js | The file icon and the cartridge on the right |
The static files come from every cartridge. With a site scope selected, the cartridges of that site's path are listed first
Go to components and editors
Cmd+Click (Ctrl+Click) on a value in a meta JSON opens what it names
| Value | Opens |
|---|---|
type_id in component_type_inclusions, component_type_exclusions or default_component_constructors | The component's JSON and its script with the same name, so the IDE asks which one to open |
type inside editor_definition | The custom editor's JSON and script |
group | Every file that declares that group |
An entry of scripts or styles in a custom editor under experience/editors | The static file. An http or https URL opens in the browser |
Cmd+Click on type_id works only inside those three arrays. Elsewhere it completes but doesn't navigate
Schemas
Every meta JSON is validated against a Page Designer schema that ships with the plugin, picked by folder: Salesforce B2C Page Designer - Pages, Components, Aspects or Editors. You get completion for keys such as region_definitions and attribute_definition_groups, and a warning for a missing required key. The list of schemas is on XML & JSON Validation
Troubleshooting
| Symptom | What to do |
|---|---|
context isn't typed in a render script | The function must be named render and the script must be under experience/components or experience/pages of a linked cartridge |
context.content. lists no attributes | Check that the meta JSON has the same name as the script and sits in the same folder, and that every attribute has an id and a type |
type_id lists nothing | The component JSON files must be under cartridge/experience/components of a linked cartridge |
Cmd+Click on type_id does nothing | The value must be inside component_type_inclusions, component_type_exclusions or default_component_constructors |
| No completion in the meta JSON | Check that your license or trial is active, see Purchase & License |