Defining and assigning variables

When designing a template, it might be necessary to calculate values or to make data attributes available in contexts where they are normally unavailable. To do this, 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 Assigning values in document specification file.

  • 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

  1. In the Outline view, click Variables > Insert > New Variable. The New Variable window opens.
  2. Enter the variable details in the following fields:
    1. Name: Enter the name of the variable.
    2. Description: Enter the description for the variable.
    3. Default Value: Enter the value for the variable.
    4. 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.

  3. To assign a variable, in Document Studio, in the editor area, right-click the element and click Data > Edit Assignments. The Assignment Editor window opens, which lists the current assignments for the element and allows you to define new assignments.
  4. Click Add. The Select Variable window opens.
  5. Enter a new name and click OK.
  6. Click OK in the Assignment Editor window.

Results

The selected variable is defined and assigned to the current element.

Feedback