E – Defining Custom Rendering Templates

This chapter explains the structure of rendering templates, and you will learn how to modify existing or create new rendering templates.

Customization of Rendering Templates

When VoiceObjects Server renders markup for the Web or text channel – i.e., HTML, XML, or any other format as expected by the respective platform or browser – it uses so-called rendering templates. VoiceObjects Server ships with a set of pre-defined rendering templates for each supported Web- or text-based media platform driver.

Creating text or Web services with these standard rendering templates provides great flexibility in customizing the look and feel of your mobile Web or text services’ GUI. In the Web channel, for example, you can use cascading style sheets (CSS) along with a set of tuning properties to adjust the GUI.

In some situations, however, you may want even more flexibility and a more personalized look. In such cases you can add your own custom rendering templates. Before going down this path, though, we recommend looking for a solution using style sheets, tuning properties, or embedded HTML code, all of which provide powerful control over the output and layout of your applications.

Standard and Custom Rendering Templates

A set of standard rendering templates is defined for each media platform driver. These standard templates are defined in the file RenderTemplates.xml

in the folder WEB-INF\config\ in your VoiceObjects installation,

and in the folder [eclipse]\plugins\com.voiceobjects.eclipseDesktop_x.y.z\config in your Desktop for Eclipse installation.

Modifications to this RenderTemplates.xml affect the entire VoiceObjects installation, i.e. all services running on a particular server. In order to define templates that are specific to a single service – or even to individual input states within a service – create a file called RenderTemplates_{VSN}.xml and deploy it to the WEB-INF\config\ directory.
{VSN} must match the VSN of the deployed service that is supposed to use it. So, if your service’s VSN is “PhoneBanking”, for example, the file name should be RenderTemplates_PhoneBanking.xml.

After deploying this file, you need to restart VoiceObjects Server to activate it.

If you want to keep VoiceObjects Server’s config folder tidy, you can deploy custom template files also to WEB-INF\config\RenderTemplates\ instead. This will make life easier when upgrading to a new version of VoiceObjects Server. When deploying to this folder, just make sure to adjust the schema location in the <templates> element by adding an extra “../” to the path:

<templates … xsi:noNamespaceSchemaLocation=
             "../../schemas/RenderTemplates.xsd">

@8  Tip: Copy existing rendering templates from RenderTemplates.xml as the basis for your own templates and modify them as required.

iconWarning328  Caution: Any change to RenderTemplates.xml or your custom template files can have impact on the functionality of VoiceObjects Server. If you are unsure about certain changes, please contact our Technical Support.

General Structure of Rendering Templates

In this paragraph, we will inspect the structure of the RenderTemplates.xml configuration file.

The root element of this XML file is <templates>. It has child elements representing the different phone channels: <text>, and <web>.

Their child elements, in turn, each represent a set of rendering templates. Each set maps to one media platform driver by referencing the respective <channelEngine> entry from the media platform driver configuration file MPDrivers.xml.

Each set consists of one or several templates for the following objects:


XML Element

Object

<promptset>

Output

<input>

Input

<summary>

Confirmation

<menu>

Menu

<exit>

Exit

<finalexit>

End of Dialog (i.e. no more objects to process). See Exiting applications for best practices on how to best finish a Web or text application.

<report>

List

 

For the List object, two templates are configured: One for the “no data”, welcome, start-of-list, and end-of-list presentation prompts (template id=0), and another one for list item output (template id=1).

The templates consist of a combination of static code, placeholders, and flags. When VoiceObjects Server’s rendering engine processes a template for a given object, the values of placeholders and flags are defined by their configuration in that object’s configuration.

The static code within each <template> element will be rendered as such, with the exception of some special elements (such as <replicator> and<voredirect>) and attributes (such as tphlink), which represent processing instructions for the rendering engine.

Object-specific custom templates

As was outlined in the previous paragraph, service-specific custom templates can be generated by creating new render template definition files for each service.

On top of that, rendering templates for individual objects can be defined by adding an attribute referenceID to the root XML elements for a given object type. The following example specifies a custom rendering template for an Output object with referenceID = “myOutput” for the XHTML mobile web driver:

<web>

  <xhtmlweb>

    <promptset>

      <template id="0">

         <!-- standard template -->

      </template>

    </promptset>

    <promptset referenceID="myOutput">

      <template id="0">

         <!-- custom template for Output myOutput -->

      </template>

    </promptset>

    ...

Instead of a single referenceID, a comma-separated list of referenceIDs may be provided in order to map the custom template to a set of objects.

For example,

<input referenceID="inpCreditCard,inpAcctDetails">

defines a custom rendering template that will be used for the two Input objects with referenceIDs “inpCreditCard” and “inpAcctDetails”, respectively.

Structural Elements of Rendering Templates

In this paragraph, the elements that are available for designing rendering templates will be presented.

The <replicator> XML element

The <replicator> element can be used to define portions of markup code that need to be iterated over for a list of items. It defines an area of code that the rendering engine must replicate 0, 1, or several times. For example, the code

<replicator tphmin="1" tphmax="-1" tphlink="ITEM">
  { code to be replicated …  }
</replicator>

defines an iteration over all items that are defined for a slot in an Input object.

These are the supported attributes of the <replicator> element:


Attribute

Description

tphmin

Minimum number of replications.

tphmax

Maximum number of replications. A value of “-1” implies no upper limit.

tphlink

This flag determines the content of the replication. For example, tphlink="HYPERLINKITEMS" defines an iterator over all hyperlinks. For more details, see Specific XML attribute below.

 

“tph” stands for template placeholder. As you will see below, these three attributes can also be applied to other XML elements.

Structurally, the <replicator> element can be used in two different ways: 1) as an iterator, and 2) as a switch. Using it as a switch will be explained in a section below.

The following table gives an overview of tphlink values that can be used with the <replicator> element to iterate over lists of available values, items, or hyperlinks.

 

Element

tphlink value

Iterate over …

[Any]

HYPERLINKITEMS

Hyperlinks

Confirmation

 

CONFITEMKEY_PREPARE

Confirmation items

CORR_ITEMS

Correction items

Input

ITEM

Possible values for a given input slot, as defined in TTG grammar

SLOTNAME

All slots as defined in the result handling of the Input object

List

 

CBNAVITEMS

Column Groups that have grammars defined

NAVITEMS

List navigation commands

SELECTITEMS

List selection commands

Menu

MENUITEMS

Menu items

 

Parameter replication

The *{token} syntax

When replications are required within a single string, such as iterations over slot names, exit parameters, or hyperlink items, the following syntax can be used:

*{token}:{min}:{max}[%{repeated content}%]

The typical use case for this structure is the concatenation of URL parameters.

For example, a URL that contains a list of parameters representing exit parameters will contain this element:

*EXITPARAMS:1:-1[%&amp;@PARAMNAME@=@PARAMVALUE@%]

Specific XML attributes

Optional attributes: The “opt-“ prefix

When you need to control whether or not to render certain attributes, a special syntax involving the prefix “opt-“ is available to be used on attribute names.

For example, the syntax

<a … opt-accesskey="ITEMKEY" accesskey="{%@ITEMKEY@%}/>

defines that the accesskey attribute is only rendered if an access key was defined in the context of the current object.


Switching elements on and off: The tphlink switch

The tphmin, tphmax, and tphlink attributes can be used to activate or suppress the rendering of XML elements. These attributes were mentioned before in the context of the <replicator> element, where they defined iterations over certain item sets.

They can be used with a slightly different meaning in a different context, working as a switch that defines whether or not to render an entire XML element. And the nice thing about this is that they can be applied to any XML element, not only the <replicator> element.

When used as a switch, the attributes tphmin and tphmax are set to 0 and 1, respectively, and the value of tphlink works as a flag.

For example, the syntax

<link rel="stylesheet" type="text/css"

      href="@STYLE_SHEET_URL@" tphmin="0" tphmax="1"

      tphlink="STYLE_SHEET_URL"/>

implies that this <link> element will only be rendered if a cascading style sheet URL is defined for the current object (i.e., a value was assigned to the tuning property Presentation - Style Sheet URL). Note that the tphmin, tphmax, and tphlink attributes will not actually be rendered; they only act as hints to the rendering engine.

Here is a list of possible values for tphlink; the first column (Element) defines the context of usage.


Element

tphlink value

True if …

[Any]

 

BOTTOM_LOGO_URL

A bottom logo URL is defined

STYLE_SHEET_URL

A style sheet URL is defined

TOP_LOGO_URL

A top logo URL is defined

Exit

 

EXITTYPE_SERVICECHAIN

The dialog exit type is Service Chaining and the exit has no output defined

NOMAINPROMPT

No output is defined

Input

CHECKBOX_STYLE

Presentation–Input for the current slot equals checkbox

MENU_STYLE

Presentation–Input=menu

OPTION_STYLE

Presentation–Input=list

PASSWORD_STYLE

Presentation–Input=password

RADIO_STYLE

Presentation–Input=radio

TEXT_STYLE

Presentation–Input=text

NON_MENU_STYLE_PRESENT

None of the defined slots is of type menu

Menu

LINEBREAK

Implicitly and dynamically set through the Tuning property Presentation-Menu (such as horizontal, vertical, or 2column)

 

To get a better understanding of the specific processing of Input objects, here is an example.

Consider an Input object with 4 slots defined in result handling: cc_type, cc_nr, cc_cv2, and cc_expdate – this is for a Web form for filling in credit card details.

We assume that the tuning parameter Presentation–Input is configured like this:

 

screenshot.png

 

Now, all the different rendering templates for the Input object in the Web channel share the same overall structure:

<replicator tphmin="1" tphmax="-1" tphlink="SLOTNAME">

  <replicator ... tphlink="OPTION_STYLE">...</replicator>

  <replicator ... tphlink="RADIO_STYLE">...</replicator>

  <replicator ... tphlink="CHECKBOX_STYLE">...</replicator>

  <replicator ... tphlink="PASSWORD_STYLE">...</replicator>

  <replicator ... tphlink="MENU_STYLE">...</replicator>

  <replicator ... tphlink="TEXT_STYLE">...</replicator>

</replicator>

The outer <replicator> element instructs the rendering engine to iterate over all slots. The inner <replicator> elements provide switches to activate, slot by slot, the code that needs to be rendered for the respective input style.

Resuming our example, the content of the replicators with tphlink =  RADIO_STYLE, TEXT_STYLE, PASSWORD_STYLE and OPTION_STYLE would be rendered, in this order, as defined by the Presentation–Input tuning parameter in the above screenshot.

Service chaining: The <voredirect> element

The special element <voredirect> is used in rendering templates for Exit objects in case the dialog exit type Service Chaining is configured.

The following example is extracted from an Exit rendering template: The <replicator> checks whether the dialog exit type is Service Chaining, and the *EXITPARAMS string will be executed at least once, up to the number of available exit parameters.

<replicator tphmin="0" tphmax="1" tphlink="EXITTYPE_SERVICECHAIN">

<voredirect target="@DESTURL@?msec=@MSEC@

*EXITPARAMS:1:-1[%&amp;@PARAMNAME@=@PARAMVALUE@%]"/>

</replicator>

Standard placeholders

Placeholders are replaced, at call time, by runtime values. They have the general form

                                @PLACEHOLDER@

i.e., they consist of an (typically uppercase) string with leading and trailing ‘@’ symbols.

An optional placeholder is marked with curly brackets and the % sign:

                                {%@PLACEHOLDER@%}

When an optional placeholder is undefined at call time, it will not be rendered into the markup code.

The following tables list all available standard placeholders, grouped in these four categories:

 1.    Placeholders that directly map to configuration of object definition and navigation;

 2.    Placeholders that map to tuning parameters;

 3.    Placeholders that are defined by the content of TTG grammars;

 4.    Placeholders that are implicitly or automatically assigned by VoiceObjects Server.


1.     Object definition placeholders

These placeholders are defined directly through the configuration of object parameters in the object editors’ Definition and Navigation sections.


Object

Placeholder

Description

Any

 

@HYPERLINKITEMPRES@

Presentation output of hyperlink

@HYPERLINKKEY@

Activation key defined for a specific hyperlink

@ITEMKEY@

Access key of Menu item or hyperlink (such as custom navigation, selection items etc.). When not assigned explicitly, auto-numbering is applied.

@OBJNAME@

Name of object

@PROMPT@

Prompt, as defined in the active Output item's prompt field

@TITLE@

Title output, as inherited from Module object definition

Confirmation

@CONF_ITEM_KEY@

Confirmation item key

@CONF_ITEM_LABEL@

Confirmation item label

@CONF_PROMPT@

Confirmation prompt

@CORR_ITEM_LABEL@

Correction item label

@CORR_ITEM_NR@

Correction item index

@CORR_ITEM_OUTPUT@

Correction item presentation output

Confirmation, Menu

@REPEAT@

For a Menu object, this reflects the setting of the field Exit Menu in a Menu item (which can be true or false). In a Confirmation object, it maps to the field Exit Confirmation in a Correction item.

Exit

*EXITPARAMS

Enumeration of Exit parameters; cf. @PARAMNAME@ and @PARAMVALUE@

@PARAMNAME@

Return parameter: Name

@PARAMVALUE@

Return parameter: Value

Input

@SLOTNAME@

Slot name as defined in result handling

@VAR_VALUE@

Value of variable that is mapped to an input slot

List

@NAVITEMKEY@

Access key defined for a List navigation command

@NAVITEMPROMPT@

Presentation output defined in the Navigation output context of a List navigation command

@SELECTITEMKEY@

Access key defined for a List selection command

@SELECTPROMPT@

List selection command - Presentation Output

Menu

@FINALPROMPT@

Menu: Selection Request

@ITEMPRES@

Presentation output of Menu item

@KEY@

Menu item access key

 

2.     Placeholders mapping to tuning parameters

The following placeholders are defined by configuring tuning parameters in the Tuning section of object editors.

 

Object

Placeholder

Description

Any

@BILLCost@

This is set as a special custom tuning parameter, with name ("Custom:") set to "BILLCost".

@BOTTOM_LOGO_URL@

Presentation - Bottom Logo URL

@CONFIDENCE@

Input - Confidence Level. This is used as the confidence threshold when measuring the Levenshtein distance in the fuzzy match of a text input against a TTG grammar. This fuzzy match is currently only implemented in VoiceObjects' IMProxy adapter.

@PROCEEDKEY@

Presentation - Proceed Key

@PROCEEDLABEL@

Presentation - Proceed Label

@STYLE_SHEET_URL@

Presentation - Style Sheet URL

@TOP_LOGO_URL@

Presentation - Top Logo URL

Input

@MAXLENGTH@

Presentation - Input Maximum Length

@SLOTLABEL@

Presentation - Slot Label

 

3.     Placeholders that are defined by the content of TTG grammars

The following placeholders are used in the context of Input objects. They are defined through the content of TTG grammars.

To give an example, consider an Input object with only one slot, gender, and this TTG grammar:

Male (m), Female (f)

In this example, iteration over the items would yield the values Male and Female for @ITEM@, and m and f for @ITEMVALUE@, respectively.


Placeholder

Description

@CHECKED@

Identifies the radio button that is pre-selected.

@CLIENTTYPE@

The syntax “client:{clienttype}” in TTG grammars for the Web channel can be used to provide hints for the client (i.e., the mobile browser) with regard to the type of required input. Examples include “client:numeric”, “client:url”, or “client:email”. This information can be accessed in the rendering template in order to define client-specific behavior. On the iPhone, for example, a typical use case is the selection of the proper keyboard (numeric vs. url-style vs. email-style) to be displayed on the touch screen. Other use cases include client-side validation of user input.

@ITEM@

Item display value (= utterance), as defined in the TTG Grammar.

@ITEM_UNCHECKED_VALUE@

Applies to slots with input style = checkbox: Defines the value that is to be assigned to a variable in case the checkbox is not selected.

@ITEMVALUE@

Contains an item's value, as defined in the TTG grammar.

@SHADOWITEM@

Contains an item's utterance, as defined in the TTG Grammar.

 

4.     Placeholders that are implicitly or automatically assigned by VoiceObjects Server

Most of the following parameters are used as URL parameters in the generated markup, and are used for internal processing by VoiceObjects Server. Their values are dynamically assigned by VoiceObjects Server, which means that you cannot change them at design time. Since the proper usage of these placeholders is important for consistent dialog processing, it is a good idea to leave the way they are used untouched.


Object

Placeholder

Description

Any

 

@DIALOGID@

Unique session ID assigned by VoiceObjects. Used as URL parameter.

@HOTLINK@

Internal hotlink parameter for RETURNURL

@HOTLINKEVENTNAME@

Internal name of hyperlink event

@LINKTYPE@

Type of hyperlink, e.g. subdialog

@MSEC@

Used as an automatically assigned URL parameter

@NAVCOMMAND@

Internal name of navigation command (for standard navigation), e.g. back, repeat, or nextRow (in List navigation)

@OBJTYPE@

Type of object, e.g. input

@RESETOFFSET@

Tells the rendering engine to reset the item counter (which is relevant in case auto-numbering of Menu items or hyperlinks is used).

@RETURNURL@

Return URL, used to render the submit statement (or form action) to get to the next dialog step.

@SUBDIALOG@

Subdialog ID for internal processing

@SUBPROC@

SubDialogProceeds parameter

@TARGET@

Internal code of target for a hyperlink.

@TIMEOUT@

Session timeout, as defined in the Service object (or as overridden by an option in the current object, e.g. Menu: "Increased dialog timeout")

Confirmation

@CORR_ITEM_SUBDIALOG@

Correction item subdialog ID

Exit

@DESTURL@

Destination URL for service chaining

Input

@VAR@

Internal name of variable mapped to a slot, e.g. var37

List

@CBNAVNAME@

Internal code for a column group; used in URLs representing column group navigation

@NAVACTION@

Internal name of a List navigation action

@SELECTITEM@

Internal code representing a List selection command

@SELECTITEMNR@

Internal index of a List selection command

Menu

@ITEMNR@

Internal number of Menu item

@MENUITEM@

Internal code for a Menu item

Custom placeholders

In addition to the standard placeholders that have been discussed in the above section, any number of custom placeholders can be defined.

This is how it works:

First, define a custom parameter in the Tuning section of your (Input, Menu, Module, …) object. The following screenshot shows an example of a parameter named myKey, assigned with the value “myValue”. For the value, you can, of course, link in e.g. a Variable or an Expression object.


screenshot.png

 

In order to reference this custom parameter in your rendering template, use the syntax

@TUNING_name@

or

{%@TUNING_name@%}

The latter syntax is used when the parameter is optional. Here, name must be replaced by the name (as defined in the Customfield) of the custom tuning parameter.

Resuming the example from the above screenshot, the placeholder you would use in the rendering templates is @TUNING_myKey@ or {%@TUNING_myKey@%}, respectively, depending on whether or not it is optional.