Skriftlig InfoDITA publishingDITA variablesVariable definitions using library topics

Variable definitions using library topics

You can use a library topic to create variables and provide these with values. The library topic must be included in your publication as a resource file.

On this page

Important

The description on this page includes a method that uses the varref attribute. This attribute is not part of the DITA standard. It is a proprietary attribute that several DITA system vendors support.

In the procedures, descriptions and examples I use the <keyword> element. In many DITA systems, you can also use other elements. The elements must be defined in the system files that control the publishing system's functionality. Check with your system supplier for more information about this.

I recommend that you standardize the use of the <keyword> element for variables. Although it is permitted to use other elements, it is easier to be consistent. This consistency increases understanding in the team and facilitates maintenance. Especially for new users, it will be easier to identify which elements are variables and which are not.

Definition of variable and value in a topic library

This is necessary code to define a variable called "VARIABLE" with a value set to "VALUE". The code will not look like this in your editor, as most editors prefer a more user-friendly presentation.

Open a topic library. Enter the following code. Feel free to put the code inside a <p> element. It is often easier to get an overview of the definitions on separate lines of text.

<p>
<keyword varid="VARIABLE">
     VALUE
</keyword>
</p>

You can create as many <keyword> definitions as you want in a library, and each can have any value you want.

If any of the values have plain text that needs translation, you must include the library topic among the files you send to the translator. If you need to do this, I recommend documenting each variable and explaining how they are used.

Tip

A standard library (library topic) is used. To identify the library and make it easier to find, I refer to it as a "Variables" library in my metadata. This identification is not a standard DITA designation. I suggest you create "Variables" as a library type in your database system. Unique identification in metadata makes the library easier to find. For more information about libraries, see DITA library topics.

Use the variable in a topic or another topic library

The variable "VARIABLE" can be used in a topic or topic library in this way:

<p>
....
<keyword varref="VARIABLE">
     VALUE
</keyword>
....
</p>

The <keyword> tag can be placed anywhere it is needed. In this example, I've used it in a <p> element, but you could just as easily place it in, say, a <title> or <cmd> element. Use the varref attribute to retrieve the correct variable.

When you use the <keyword> tag in a topic or topic library, the content of VALUE can be any random text. You can also type whatever you want in the <keyword> tag. When the document is published, the publishing process will automatically retrieve and insert the correct value from the definition. This automatic process means you can insert the <keyword> tag from any topic library or copy it from another topic. Just make sure the varref attribute points to the correct variable.

Place the topic library with the definition in the publication

The library of <keyword> definitions must be inserted into the publication as a resource file. Do this in the publishing program.

Tip

These pages only explain how variables are used in DITA publishing. If you want additional explanations about the principle of variables, see under Methodology and especially Using variables in the text.


All external links open in a new window. I take no responsibility for information on external websites, even if I have linked to them. Please report links that do not work.

The information on this page represents my personal opinions and my understanding of the topic being described. Feel free to link to the page, but do not copy large parts of the content without permission. I take no responsibility for any errors, misunderstandings or missing information. I also take no responsibility for any mistakes you may make or cause as a result of incorrect or missing information. You are welcome to contribute with comments, relevant experiences or additional information. See Editor and contact information.