Component attribute definitions, UI controls and resolved values
Key Takeaway
An attribute's type sets two things: the UI control the merchant uses, and the resolved value the component script reads from context.content. For an image attribute, the script gets a dw.experience.image.Image object. It does not get the stored JSON or a file path.
Page Designer components get their merchant-editable settings from attributes declared in the component type's JSON meta definition file. The merchant sets each value in the Business Manager visual editor, using the UI control that the attribute's type selects. When the component renders, the script receives those values in a map. Where needed, each value is already converted into a B2C Commerce API object, so your code works with objects rather than stored strings.
Declaring attributes
A component type's meta definition file declares the attributes a merchant can set, such as an image, a heading or a category link. Each attribute definition has an id, a name and a type. An attribute can also be marked required.
Attributes sit inside attribute_definition_groups. Each group has its own id, name and description. The visual editor shows a group's attributes together under the group's name.
{
"name": "Seasonal Promo",
"description": "Promo tile with an image, a headline and a category link",
"attribute_definition_groups": [
{
"id": "promoVisual",
"name": "Promo Visual",
"description": "The image shown in the promo tile.",
"attribute_definitions": [
{ "id": "heroImage", "name": "Hero Image", "type": "image", "required": true }
]
},
{
"id": "promoText",
"name": "Promo Text",
"description": "The headline and the link target.",
"attribute_definitions": [
{ "id": "headline", "name": "Headline", "type": "string" },
{ "id": "shopCategory", "name": "Shop Category", "type": "category", "required": true }
]
}
]
}In the visual editor, the merchant sees two groups: "Promo Visual" and "Promo Text". heroImage and shopCategory are required, but headline is optional.