Storing and Recalling Texts

A piece of text can be stored in an export variable and recalled in a different place in a layout by means of instructions like in the following example:

<npsobj modifyvar="set" varname="myvar">
  Author of this document: <npsobj insertvalue="var" name="author" />
</npsobj>
...
<npsobj insertvalue="var" name="export.myvar" />

This code assigns to the variable myvar the character string Author of this document:, followed by the value of the field author. Subsequently, the value of this variable is output. You may also access the value of the variable using the following code:

<npsobj insertvalue="var" name="myvar" />

However, because the export. prefix has not been specified, an unwanted content dependency for the current file context is generated if the variable does not exist.

During the export of the respective file, myvar can be read any number of times, unless this variable is deleted with the following instruction:

<npsobj modifyvar="clear" varname="myvar" />

The variable can also be accessed in included layouts (insertvalue="template"). However, this may quickly lead to incomprehensible layouts because the value of the variable can not be spontaneously determined from the included layout. Therefore, variables should only be used in layouts in which a value is assigned to them.

If a variable is to be assigned the value of a field only, i. e. no literal text, then this can be done directly in the instruction’s tag:

<npsobj modifyvar="set" varname="myvar" name="parent.title" />

The names of export variables have precedence over the names of fields. You can, for example, create a variable named toclist and assign it a character string. Afterwards, however, you will not be able to have a table of contents generated using <npsobj list="toclist">. By means of the prefix self, however, the content or file field of the same name can be referenced again ("self.toclist").