When you learned how to create headers and footers in "Headers and Footers", you probably noticed the %PAGENUM%, %PAGETOTAL%, and %H1% variables. When Highwire sees these variables in your header or footer, it automatically replaces them with the current page number, total number of pages, and the contents of the last <h1> tag, respectively. These variables are built-in to Highwire.
With Highwire's <ctvar> tag, you can define your own variables. Variables, which must begin and end with a percentage sign (e.g. %USERNAME%), can be used as placeholders in headers and footers for information that may change on a document-by-document, or even page-by-page basis. When Highwire sees these variables in a header or footer, it will replace them with text or an HTML string of your choosing.
A variable should be defined using the <ctvar> tag in the <head> section tag of your document. It can be redefined using a <ctvar> tag at any point in your document. You should set the name attribute of this tag to the variable name (remember to begin and end the name with a percentage sign), and the value attribute of this tag to the text or HTML code with which Highwire should replace the variable.
For example, the code below defines a variable of %AccountOwner% with a value of John Doe.
<!-- <ctdocvar value="John Doe" name="%AccountOwner%" /> -->
This variable could be useful, for instance, if we were to put it in the <head> tag of a document that linked to a Highwire template file with the following header definition:
<ctheader><p>Quarterly 401k Account Report for %AccountOwner%</p></ctheader>
When Highwire creates this PDF document, the resulting header will be:
<p>Quarterly 401k Account Report for John Doe</p>
This allows us to use the same header for many documents (since the header is in a Highwire template file), but to change the name used in the header on a document-by-document basis with the <ctvar> tag.
The <ctvar> tag also allows us to change headers and footers on a section-by-section basis. For example, suppose we have a web document that is divided into a number of chapters. To get the footer to change whenever we start a new chapter, we could create the following footer:
<ctfooter><p align="right">Chapter %CHAPTERNUM%, "%CHAPTERTITLE%"</p></ctfooter>
Then, whenever we start a new chapter in the document, we could define the %CHAPTERNUM% and %CHAPTERTITLE% variables so that they reflect the current chapter. The example below illustrates this technique.
Example 6.9 Using Section Variables for Footers
<html><head>
<!-- <ctfooter><p align="right">Chapter %CHAPTERNUM%, "%CHAPTERTITLE%"</p></ctfooter> -->
<!-- <ctvar name="%CHAPTERNUM%" value="1"/> -->
<!-- <ctvar name="%CHAPTERTITLE%" value="Introduction"/> -->
</head><body>
<h1>Chapter 1, Introduction</h1>
...
<br style="page-break-before:always"/>
<!-- <ctvar name="%CHAPTERNUM%" value="2"/> -->
<!-- <ctvar name="%CHAPTERTITLE%" value="Getting Started"/> -->
<h1>Chapter 2, Getting Started</h1>
...
</body></html>
Note: The task above could more easily be accomplished with the %H1% pre-defined variable. See Table 3.1 on page 3-13 for information about this variable.
CORDA