### 12.4 Deploying user variables in template macros

One of the advantages of DITA2Go user variables is that they provide a way to produce additional output that is separate from the main document output stream, and that includes metadata. This allows you to do things such as construct title pages and generate lists. To produce such output, you deploy user variables in a template macro. A template macro is a macro whose name is assigned to an external file name. A macro template associates a template macro with a file name.

To assign a template macro to a file:

    [MacroTemplates]
    ; filename.ext for template output doc = template macro name
    filename.ext = macroname
    ; or:
    filename.ext = path/to/macro/file

The name of the file to which you assign the template macro must include an extension, and may include a path. The default location for the file is the output directory.

The template macro name can refer to any of the following:

- a macro defined in your project configuration file
- a macro defined in a macro library file referenced by your configuration file (see §37.2.4 Including macro definitions in your own macro library)
- a file that contains only the template macro.

This example assigns a template macro named $BookTitlePageTemplate to an output file named booktitlepage.htm located in the output directory:

    [MacroTemplates]
    booktitlepage.htm = BookTitlePageTemplate

Variable maptitle is assigned to the map title for the document:

    [VariableMaps]
    title/map/1 = maptitle

The content of variable author (element author is automatically a variable; see property Var in Table 11-1) is replaced with a new value:

    [MacroVariables]
    author = Omni Systems

The template macro is defined in the configuration file:

    [BookTitlePageTemplate]
    <html><head>
    <title><$$maptitle></title>
    </head><body>
    <h1><$$maptitle></h1>
    <p class="author">By <$$author></p>
    </body></html>

When <$BookTitlePageTemplate> is invoked, DITA2Go writes the following to file booktitlepage.htm in the output directory:

    <html><head>
    <title>DITA Test Suite</title>
    </head><body>
    <h1>DITA Test Suite</h1>
    <p class="author">By Omni Systems</p>
    </body></html>

Previous Topic: 12.3 Including user variables in DITA2Go macros

Next Topic: 13. Processing related and associative links

Parent Topic: 12. Creating and deploying user variables

Sibling Topics:

12.1 Understanding how DITA2Go user variables work

12.2 Assigning variable names to element paths

12.3 Including user variables in DITA2Go macros