Skip to main content

Defining templates

What is a template?

Templates define the page's structure.

For example, a template divides the page into:

  • Header
  • Main section
  • Footer

Templates can nest layouts and modules, but not other templates.

The next paragraph describes the JSON fields that define templates.

Defining templates

The templates' definition is a JSON array of template definitions.

The fields that define a template are:

NameTypeIs MandatoryDescription
keyObjectYesRepresents the unique human-readable identifier of the template
slotsArray of stringYesList of container names (slots) that can contain layouts or modules
labelStringYesFriendly name of the template shown on the Page Builder
descriptionStringNoDescription of the template shown as helper in the Page Builder
designObjectYesIt defines the template's structure in terms of number of rows. For each row, it defines the row's number of columns. In turn, each column can be split in rows. The rows definition is recursive.
propertiesObjectYesProperties defined on this module

key (object fields)

NameTypeIs MandatoryDescription
idStringYesUnique identifier (PascalCase, no spaces)
namespaceStringYesGroup of templates the template belongs to. By convention, use the format {page-type-name}_Template.

design (object fields)

Based on the slot names, the design object defines the structure in which the slots are located within templates and layouts.

The model structure consists of an array of rows. Each row consists of an array of columns whose Name property must match the name of a slot.

In the example below, the design object contains the object rows with three rows corresponding to the header, main, and footer slots. Each row contains an object columns with a single column. The Name field of each column contains the slot's name. The header and footer columns have elementType=1 to setting that those slots are not available (Slot Locked) in the Page Builder design page to host layouts and modules.

alt text

nameTypeIs MandatoryDescription
rowsArray of columnsYesList of columns in the containing row

columns (object fields)

columns is an array of objects defined each by:

NameTypeIs MandatoryDescription
elementTypeIntegerYesIt sets if the slot is available in the Page Builder design page to host layouts and modules (0), if the slot is locked (1), if the column contains nested rows (2)
nameStringNoName of the area represented by the column, must match slot name
descriptionStringNoDescription of the area shown in editing view
widthIntegerYesThe width value is interpreted as a fraction of the sum of the widths in a row. For example, in a row with 3 columns, which have width values of 20, 40, and 10, the design draws columns with a percentage width of 20/(20+40+10)=28.6%, 40/(20+40+10)=57.1%, and 10/(20+40+10)=14.3%
rowsArray of columnsYesNested rows within this column

properties (object fields)

properties is an array of objects defined each by:

NameTypeIs MandatoryDescription
nameStringYesUnique identifier of the property
typeNameStringYesType of data assigned to the property. Supported values: String, Int32, Boolean or extended types offered by FORGE)
categoryStringNoGroup representing the category of this property
descriptionStringNoHelper text shown in Page Builder
displayNameStringNoFriendly name shown in Page Builder
isBrowsableBooleanYesField visibility on the UI
pickListObjectNoList of possible values for the property
contentPickerObjectNoConfiguration for content selector to assign to property

Configuration to Avoid

When defining templates, avoid the following common configuration issues:

  • Duplicate property names: Each property in properties must have a unique name. Duplicate names are not allowed.
  • Conflicting controls: A property cannot have both ContentPicker and PickList defined at the same time.
  • PickList type restriction: The PickList can only be used with properties where typeName is String.
  • ContentPicker type restriction: The ContentPicker can only be used with properties where typeName is String or CmsArray.

Sample

The simplest template — let's call it Default — defines three rows:

  • Header: A single column row that the Page Builder design page cannot fill with layouts and modules.

    Pages with this template must define a variable — let's call it page_header — containing the path of the page the front-end must render within the header slot. This variable can have a default value and change where a different header is needed.

  • Main: A single column row that the Page Builder design page can fill with layouts and modules.

  • Footer: A single column row that the Page Builder design page cannot fill with layouts and modules.

    Pages with this template must define a variable — let's call it page_header — containing the path of the page the front-end must render within the footer slot. This variable can have a default value and change where a different footer is needed.

alt text

The Default template's JSON definition is the following:

"root": {
"key": {
"id": "Default"
"namespace": "type_Template"
}
"slots": [
"0": "header"
"1": "main"
"2": "footer"
]
"label": "Default"
"design": {
"rows": [
"0": {
"columns": [
"0": {
"elementType": 1
"name": "header"
"description": "Header Slot"
"width": 100
"rows": [
]
}
]
}
"1": {
"columns": [
"0": {
"elementType": 0
"name": "main"
"description": "Main Slot"
"width": 100
"rows": [
]
}
]
}
"2": {
"columns": [
"0": {
"elementType": 1
"name": "footer"
"description": "Footer Slot"
"width": 100
"rows": [
]
}
]
}
]
}
"properties": [
]
}