# Template syntax

## Availability

\[SINCE Orbeon Forms 2018.1]

Templates apply to:

* Email Settings
  * Subject
  * Body
* Control Settings
  * Label
  * Hint
  * Help Message
  * Explanatory Text \[SINCE Orbeon Forms 2019.1]

## Templates

You define a template by setting a placeholder with the following syntax:

```
{$foo}
```

where `foo` is a name which must match one of the template parameters configured below.

## Template parameters

You can add new parameters with the "+" icon and remove them with the "-" icon.

The following options are available for each template parameter:

<figure><img src="https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LEkBiSDvlXs3VWiO0Zu%2Fuploads%2Fgit-blob-264298a8f9c054e7124b6d38a4000f8a09a727da%2Ftemplate-parameter-options.png?alt=media" alt="Template parameter options" width="148"><figcaption><p>Template parameter options</p></figcaption></figure>

* Parameter name: this must be unique among parameters.
* Parameter value:
  * **Control Value:** the value of a form control.
  * **XPath Expression:** calculated expression.
  * **All Control Values:** the value of all form controls.
    * This is only available for the email body.
    * This is experimental as of Orbeon Forms 2018.1.
  * **Links** \[SINCE Orbeon Forms 2020.1]
    * Links are available for the following:
      * Email Body
      * Label
      * Hint
      * Help Message
      * Explanatory Text
    * Links include:
      * Link to the "edit" page
      * Link to the "view" page
      * Link to the "new" page
      * Link to the "summary" page
      * Link to the "home" page
      * Link to the PDF file
  * **Automatic PDF only** [\[SINCE Orbeon Forms 2023.1\]](https://doc.orbeon.com/release-notes/orbeon-forms-2023.1)
    * Image (form logo by default)
    * Form title
    * Page number
    * Page count

*NOTE: For the email subject and body, an XPath expression runs in the context of the form data's root element. However, the* [*Form Runner function library*](https://doc.orbeon.com/xforms/xpath/extension-functions/extension-form-runner) *is not yet available to expressions as of Orbeon Forms 2018.1. For labels, hints and help messages, the Form Runner function library is available.*

A template may omit references to any or all template parameters.

## Links

\[SINCE Orbeon Forms 2020.1]

Links are intended to point to some Orbeon Forms pages or resources (namely, the PDF file). The end user might see such links in explanatory text and email bodies, in particular.

<figure><img src="https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEkBiSDvlXs3VWiO0Zu%2F-M4Uik0YvALonqST3SbT%2F-M4UilXSzCfo29i3G1n1%2Ftemplate-parameter-links-example.png?generation=1586449030236823&#x26;alt=media" alt="Links in an email template" width="802"><figcaption><p>Links in an email template</p></figcaption></figure>

To insert the URL, you use the template syntax within the "URL" field of the link dialog:

<figure><img src="https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEkBiSDvlXs3VWiO0Zu%2Fsync%2Fda4b18a94f8cdc0cc0ea7b45d45cc5e5fffecb60.png?generation=1593110546549524&#x26;alt=media" alt="Editing a link URL" width="482"><figcaption><p>Editing a link URL</p></figcaption></figure>

Form Runner requires the ability to know how to reach Form Runner. In some cases (use of a reverse proxy), Orbeon Forms cannot determine this automatically. For this purpose, the following property allows setting the external Form Runner URL. By default, it is empty, and can set it to an absolute URL as follows:

```xml
<property 
    as="xs:string"
    name="oxf.fr.external-base-url"
    value="https://orbeon.acme.org/forms"/>
```

You can't use links to point back to Form Runner when using [embedding](https://doc.orbeon.com/form-runner/link-embed/java-api) or the \[ [Form Runner proxy portlet](https://doc.orbeon.com/form-runner/link-embed/liferay-proxy-portlet).

## Localization

When the form definition has more than one language:

* Each language has its own localized template.
* Template parameters are not localized and are available no matter what language is selected.

## Examples

In the following example of a dynamic control label, the `$name` variable refers to the subsequent `name` parameter. The Template Parameters section declares that `name` parameter to refer to the `name` control.

<figure><img src="https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEkBiSDvlXs3VWiO0Zu%2F-LImUI-s4XdNuE_d1HEH%2F-LImUPKirryB_JmDLxOc%2Fcontrol-settings-label-dynamic.png?generation=1533076681294826&#x26;alt=media" alt="Dynamic label configuration" width="942"><figcaption><p>Dynamic label configuration</p></figcaption></figure>

This is how this would appear in the running form:

<figure><img src="https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEkBiSDvlXs3VWiO0Zu%2F-LImUI-s4XdNuE_d1HEH%2F-LImUPKkm1VXRZ4-udcg%2Fcontrol-settings-label-dynamic-runtime.png?generation=1533076680490317&#x26;alt=media" alt="Dynamic label at runtime" width="362"><figcaption><p>Dynamic label at runtime</p></figcaption></figure>

In the following example of dynamic email subject, the `$title` and `$author` variables refer also to the subsequent parameters.

<figure><img src="https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEkBiSDvlXs3VWiO0Zu%2F-LFZt2gpdgtXSCCHe0-f%2F-LFZtEcvvfVnf-hiy65c%2Femail-settings-subject.png?generation=1529627345314154&#x26;alt=media" alt="Email Subject" width="802"><figcaption><p>Email Subject</p></figcaption></figure>

The text of the template is localized as usual when the form definition has more than one language.

## See also

* [Control settings](https://doc.orbeon.com/form-builder/form-editor/control-settings)
* [Email settings](https://doc.orbeon.com/form-builder/advanced/email-settings)
