When designing a template, it might be necessary to calculate
values or to make data attributes available in contexts where they
are normally unavailable. For these situations, you can define variables
and assign them values. The values can be static data or can be data
available in the current context.
About this task
Variables can be used as placeholders for data calculated
at runtime (variable assignments) or can be provided in the document
specification. Unlike data attributes, you can also use variables
in master pages.
There are two types of variables:
- User-defined variables: User-defined variables are defined by
the template designer. A user-defined variable can be internal or
external.
- Internal user-defined variables: Specify a variable as internal
to perform calculations or to temporarily store information, such
as a variable that is used to bring data into the master pages. Internal
variables are not displayed in the document specification; therefore,
you cannot provide them with values.
- External user-defined variables: Specify a variable as external
when you provide it with a value. External variables are displayed
in the document specification. See Creating a document specification.
- Rational® Publishing Engine variables: Rational Publishing Engine variables
are internal variables available for use in the document template.
Table 1. Internal variablesVariable |
Description |
_element_id |
Kept internally in the template and
used for debugging. |
_element_level |
The recursive level of an element. |
_row_number |
The row number in a current table.
If the element is not a row the value is 0. |
_cell_number |
The cell number in a current row. If
the element is not a cell the value is 0. |
Procedure
- In the Outline view, click . The New Variable window
opens.
- Enter the variable details in the following fields:
- Name: Enter the name of the variable. The variable name must use valid Java™ or
JavaScript identifiers since they are used in scripts.
- Description: Enter the description
for the variable.
- Default Value: Enter the value
for the variable.
- Access: Select whether the variable
is internal or external from the list.
- Internal variables are not displayed in the document specification,
so you cannot provide them with values.
- External variables are displayed in the document specification
and you can provide values to them.
- To assign a variable to an element:
Tip: Assign variables to container elements whenever possible.
The variable is applied to the elements within the container element.
For example, you might want to use a variable within a table so that
a new row is created for each variable. If you assign a variable to
the table element, a table might be created for each variable. Sometimes
these consecutive tables merge, but sometimes they display as separate
tables. If you add a container element inside the table and drag the
row into the container element, then assign the variable to the container
element, a single table is created with rows for each variable.
- Right-click the element and click . The Assignment Editor window
opens.
- Click Add. The Select
Variable window opens.
- Enter a name for the variable and click OK.
- Click OK in the Assignment
Editor window.
Results
The selected variable is defined and assigned to the current
element.
When you assign a variable to an element,
the element displays an
icon in the template content
editor.
What to do next
Tip: You can search
for a list of variable assignments used in an element by right-clicking
the element the variable is assigned to and selecting . The Search view opens and a list of variable assignments
displays. You can double-click a variable assignment in the results
to edit it.You can search for a list
of variable assignments, attributes, and queries used in an element
by right-clicking an element and selecting . The
Search view opens and a list displays. You can double-click an item
in the results to edit it.