Create Templates for Form Layouts

You can apply a form template to layouts to control how it's rendered, including which fields you want the layout to contain and how they are displayed in the layout. The template can be one of the templates defined in a dependency, or it could be your own form template. For example, you might have a page that uses a dynamic form to display a detail view that includes contact details, and you want the form to always display a Rating Gauge component, regardless of which fields are defined in the layout. You could create a 'Leads' form template that includes the Rating Gauge component, and then apply the template to the form. You can re-use the template in multiple form layouts in a Layout's rule sets, but templates can't be shared between Layouts.

To create a form template for a dynamic form:

  1. Open the Layout's Templates tab.

    The Templates tab displays a list of field and form templates that are already defined for the Layout. Templates that are defined in a dependency will have a badge that displays the name of the dependency.



    If you want to duplicate a template that you've created, open the template's menu and select Duplicate. You can also use the menu to edit, delete, and view the code of templates you've created.



    You can also duplicate templates defined in dependencies, but only if the template only contains a fragment (or fragments).

  2. Click Add Template and select Form in the dialog.
  3. Specify the Label and ID. Click Create.

    The new template opens in the form template editor. The form template editor contains a Components palette, Structure view, canvas and Properties pane.

    In this image, you can see that the canvas has two read-only template fields that are generated automatically: Additional Fields and Remaining Required Fields. These fields are used to display the data and display names for the fields defined in the layout. These template fields render all the fields in the layout, so you don't need to modify the template each time you change a layout.



  4. While Form Template is selected in the editor, click Add item in the Extra section in the Properties pane.

    The Extra fields are fields that are defined in the template, not the layout. Each field you add in the Extras section is displayed in the form when the template is applied, and can't be removed in the layout.

    Each Extra field must be mapped to a component if you want it to appear in the form. This image shows the Properties pane after adding the BrandName field to the template as an Extra.



  5. Drag the component you want to add from the Components palette and position it in the Structure view or on the canvas.


    You can add components above and below the read-only template fields, but not within them. In the Structure view of this template, you can see an Input Text component that was positioned above the Additional Fields template in the Form Layout.



  6. While the component is selected on the canvas or in the Structure view, open the component's Data tab in the Properties pane and bind the component to the Extra reference field.

    To help you select the reference field, you can click fx iconto open the Expression Editor, or Select Variable to open the Variables picker.



    To write efficient expressions that handle situations where a referenced field might not be available or the field's value could be null, see How To Write Expressions If a Referenced Field Might Not Be Available Or Its Value Could Be Null.

After you've added the components and fields to your form template, you can apply the template when you edit a layout in the Rule Sets editor.

Apply a Template to a Form

To apply a form template to a form:

  1. In the Rule Sets tab, open the rule set for the form you want to work on.
  2. Click the name of the layout to open it in the layout editor.
    The center pane of the layout editor lists the fields that will be displayed in the layout and the templates that are applied to them.
  3. While the form is selected, click Use Template in the Properties pane.


    If a template has already been applied to the form and you want to switch to a different one (or remove it), click Select in the Properties pane. The list of templates will include form templates defined in your dependencies as well as the templates you've created.

    You can click Create in the Properties pane if you want to create a new form template.

  4. Select the template you want to apply in the Use Layout Template window. Click Select.

    The Use Layout Template window displays the templates you can apply to your form layout. In addition to templates you've created, the window will also include form templates defined in your extension's dependencies that you can apply

    You can also select Create a New Template to create a new form template.

When a template is applied to a form layout, the template name and the fields defined in the template are displayed above the list of fields in the layout. In this image of the layout editor, you can see the header displays the name of the template (NewOrganizationCardLayoutTemplate) applied to the form layout, and the fields defined by the template (altName, origin).



You can't edit templates defined in dependencies, but you can edit the fields defined in templates you've created. To open a template you've created, click Go to Template in the Properties pane.

If you select a template that contains a field you don't want to appear in your form, you'll need to select a different template, or click Select to open the Use Layout Template window, and then select No Template.