Page Designer

Typed render scripts, context.content from the meta JSON, and completion and navigation in Page Designer component and page JSON

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

In Page Designer meta JSON, 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 JSON

Before you start

NeedsWhy
Files in cartridge/experienceThe plugin recognizes Page Designer files by folder: experience/components, experience/pages, experience/editors and experience/aspects
A linked cartridgeRender scripts are typed only in linked cartridges, see Cartridges & Modules
A valid license or trialCompletion 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) { ... }

ParameterIn a component scriptIn a page script
First, contextdw.experience.ComponentScriptContextdw.experience.PageScriptContext
Second, modelIndw.util.Mapdw.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

cartridge/experience/components/commerce_assets/heroBanner.json
{
  "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" }
      ]
    }
  ]
}
cartridge/experience/components/commerce_assets/heroBanner.js
'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 typeMember type
stringstring
booleanboolean
integerint
categorydw.catalog.Category
cms_recorddw.experience.CMSRecord
customdw.util.Map
filedw.content.MediaFile
imagedw.experience.image.Image
pagedw.experience.Page
productdw.catalog.Product and dw.catalog.Variant
Any other type, such as text, markup, enum or urlstring

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

ValueCompletesEach item shows
groupEvery group declared in a Page Designer JSON fileThe group name
type_id, for example in component_type_inclusionsComponent type IDs from experience/components, as a dotted path such as commerce_assets.heroBannerThe JSON file icon, the word components and the cartridge on the right
type inside editor_definitionCustom editor type IDs from experience/editorsThe JSON file icon, the word editors and the cartridge on the right
scripts and styles arraysJavaScript and CSS files from the static folders of your cartridges, as a path below the locale folder such as /js/editors/colorPicker.jsThe 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

ValueOpens
type_id in component_type_inclusions, component_type_exclusions or default_component_constructorsThe component's JSON and its script with the same name, so the IDE asks which one to open
type inside editor_definitionThe custom editor's JSON and script
groupEvery file that declares that group
An entry of scripts or styles in a custom editor under experience/editorsThe 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

SymptomWhat to do
context isn't typed in a render scriptThe function must be named render and the script must be under experience/components or experience/pages of a linked cartridge
context.content. lists no attributesCheck 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 nothingThe component JSON files must be under cartridge/experience/components of a linked cartridge
Cmd+Click on type_id does nothingThe value must be inside component_type_inclusions, component_type_exclusions or default_component_constructors
No completion in the meta JSONCheck that your license or trial is active, see Purchase & License

On this page