How to – Pass variables to a template

Avatar
How to - Pass variables to a template

In this post we’ll show you how to use runtime parameters to effortlessly pass variables to a template. Runtime parameters provide an elegant way to pass information from Workflow into the document creation process without having to modify the data records or data model. Keep reading to learn more!

Information that is needed to personalize a template sometimes only becomes available when a production process is running. To give a few examples:

  • The name of the email section to use.
  • Paths to dynamic background images or stationery.
  • The subject or the sender name for an email batch.
  • The location to send form data to, in the case of Capture OnTheGo.
  • The printer’s non-printable areas.

In the past, production related information could only be passed to a template via the data. You may have found yourself adding the information to the ExtraData field or changing the data mapping configuration. That is no longer necessary.
As of OL Connect version 2020.2, runtime parameters for content creation allow to pass variables to a template. The values of these parameters are dynamically set by Workflow and are then directly accessible in the template and available with all records in the data set.

Defining a runtime parameter

The Parameters pane in the Designer provides the ability to view, add and change runtime parameters for templates. It is found next to the Data Model pane.

To add a runtime parameter:

  1. Select the Parameters pane.
  2. Click the Add parameter icon (plus-symbol). The Add parameter dialog appears.
  3. Enter a name for the parameter.
  4. Enter a default value.
  5. Click OK to save the parameter.

The default value is used when a parameter is not set in the Workflow process.

Parameters pane in Designer

Passing a value from Workflow

In Workflow, the various Content Creation tasks display the list of runtime parameters that are expected by the template you select.

Runtime Parameters in Workflow

By default, each runtime parameter displays the default value that was specified in the template, but you can change the values to use any of the dynamic values available in Workflow, including data/metadata selections.

Using the runtime parameter value in a script

The runtime parameter defined in the above example provides the path to a dynamic media background image. The Control script to use that value could look like this:

let media = merge.template.media;
if( merge.template.parameters.stationeryPath ) {
  let stationeryPath = merge.template.parameters.stationeryPath; 
  media['Media 1'].stationery.front.enabled = true;
  media['Media 1'].stationery.front.url = stationeryPath;
}

The parameters are accessed via the template property of the merge object.

The following script sets the action of an HTML form in a Capture OnTheGo template. The selector of the script refers to the <form> element (not shown here).

var cotgHost = merge.template.parameters.cotgHost;
results.attr('action', cotgHost);

Tip: Runtime parameters also exist for other tasks – data mapping, job creation and output creation – and are used in much the same way.

Tagged in: parameter, Template



Leave a Reply

Your email address will not be published. Required fields are marked *