When designing a template, it might be necessary to calculate
values or to make data attributes available in contexts where they
are normally unavailable. Define variables and assign them values.
The values can be static data or 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. The variables are of two types:
- User-defined variables: User-defined variables are defined by
the template designer. A user-defined variable can be internal or
external.
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.
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.
Variable |
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.
- 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; hence you cannot
provide them with values.
External variables are displayed in
the document specification and you can provide values to them.
Note: Creating
external variables is preferable to hardcoding data source URLs in
your template. If you hardcode URLs and the server name changes, then
you must update the URLs in every template. With external variables,
you can override the URLs at run time. For templates that are embedded
in other products, use the special variables that are recognized by
those products when they are referencing data.
- 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.