Edit

Work with templates

This article describes how to work with templates in Microsoft Dynamics 365 Commerce.

As explained in Templates and layouts overview, templates define the set of options that downstream authors can use. Templates are useful to an enterprise's web authoring team for several reasons. Well-structured templates can help with all the following goals:

  • Simplify the authoring experience for day-to-day content editor roles.

    • Filter module options so that only relevant modules are shown for a specific page section. For example, you can configure a marketing section of a template to filter out irrelevant modules that should never be used in that context.
    • Configure default module setting to help improve authoring efficiency.
    • Define default page fragments to help improve authoring efficiency. For example, header and footer fragments in a template automatically appear on every downstream page.
  • Keep enterprise sites on-brand by defining an approved set of module arrangement and configuration options.

    Tip

    Successful e-commerce sites provide customers with familiar, repeatable, and on-brand user experience (UX) design patterns. By using templates, you help control consistency across your site.

  • Improve search engine optimization (SEO) scores by ensuring repeatable and programmatically defined page definitions and metadata.

Note

Although templates are designed to control consistency across a site, you can theoretically configure them so that they don't enforce any consistency. Brand and site administrators can define any level of variability for the pages on their site. For example, a template can be left entirely open, so that content authors can create any page design that they choose. In this case, none of the benefits in the preceding list are applicable.

Modify a template

Use the template editor to modify templates.

To open the template editor in Commerce site builder, follow one of these steps:

  • In the navigation pane of your site, select Templates, and then select the template to modify.
  • In the page editor for an existing page, select the top node in the outline tree on the left. Then, in the property pane on the right, select Edit Template.

The outline tree view on the left shows the module options and structures that are available to child layouts and pages. When you select a module in the outline tree, you can view the template properties for the selected module in the property pane on the right. Some of these properties are unique to template editing. The following table describes these properties.

Property name Description
Min Occurs This property defines the minimum number of occurrences for the selected module. For example, if you set the value to 1, the module is required for downstream authors. If you set the value to 0 (zero), the module is optional.
Max Occurs This property defines the maximum number of occurrences for the selected module. For example, if you set the value to 1, you can add the module only one time.
Min Modules (Containers) For modules that contain other modules (that is, for containers modules), this property defines the minimum number of total modules that you add as children. For example, for a carousel module, you might set the value to a number higher than 1.
Max Modules (Containers) For container modules, this property defines the maximum number of total modules that you add as children. For example, for a carousel module, you might set the value to a number less than 10.
Locked A Locked Boolean control appears next to all core module properties. It lets the template author lock a module setting in the template. A locked module setting can't be overridden by any child layouts or pages. It becomes a centrally editable property value for all layouts and pages that use the template.

Create a new template

To create a new template in site builder, follow these steps:

  1. In the navigation pane of your site, select Templates to open the template inspector view.
  2. Select New Template.
  3. In the template creation dialog box, enter a name and description for the template. Authors see these values when they create new pages, so enter metadata that's useful to page authors. For example, enter Use this template to create general marketing pages as the description. You can edit this metadata later.
  4. Select OK to create the new template and open the template editor. The template editor shows an outline tree and a property pane.
  5. In the outline tree, expand the nodes, and select the HTML Head slot.
  6. If this slot doesn't yet contain any modules, select the ellipsis button (...), and then select Add Module.
  7. In the Add Module dialog box, select Default page summary, and then select OK.
  8. In the outline tree, select the new module, and then, in the property pane, enter any default settings that should be automatically configured for all child pages of the template. If you don't want any default settings, leave the values blank.
  9. In the outline tree, select the Body slot, select the ellipsis button, and then select Add Module.
  10. Select a page container module (there might be only one option), and then select OK.

Under the new page container module, you see a new set of slots (Header, Main, and so on). Add and configure the module options that authors can use when they create pages from this template. By default, if you don't add any modules to a slot, all available module types are supported for that slot.

The template is now technically valid. You can save it, check it in, and use it to create new pages. However, the next three sections describe some other default settings that you might want to configure first.

If your site already has a header fragment, follow these steps in site builder to add a header and a footer to a template.

  1. In the outline tree, expand the Body slot and its child page module.
  2. Select the Header slot.
  3. Select the ellipsis button for the Header slot, and then select Add Fragment.
  4. Search for and select your site's header fragment, and then select OK.

All pages that use the template now automatically inherit this header fragment.

If your site doesn't yet have a header fragment, see Create a fragment for information about how to create it, and then complete the previous procedure.

Change the template theme

To set the default theme for all pages that use a template, follow these steps in site builder.

  1. In the outline tree, expand the Body slot.
  2. In the Body slot, select the page container module (for example, Default Page).
  3. In the property pane, in the Theme field, select a theme.

By default, all new pages now use the selected theme. To prevent pages from overriding this setting at the layout or page level, set the Locked Boolean control to True.

Add a script to a template

Add HTML