How Do I Create a Dynamic Table of Contents for my Template?
The approach is exactly the same as adding a Table of Contents to a static Word document the only difference is we will be applying the styles used in the TOC to our Windward tags.
The TOC (Table of Contents) field builds a table of contents. The TOC field collects entries for a table of contents using heading styles, other specified styles, outline levels, captions, or entries specified by TC (Table of Contents Entry) fields. Word inserts the TOC field when you click Table of Contents in the Table of Contents group on the References tab. Windward offers a sample TOC template you can find in the following directory after installing the Designer.
%USERPROFILE%\Documents\Windward\templates\Table of Contents - Sample.docx
You can see in the image below the TOC looks generic as the dynamic content has not yet been generated from the template so you see Heading1 and Heading2 as entries.
If you hold down the Alt key and then hit F9 (Alt-F9) you will reveal the field codes used in your template. As you can see from the image below the TOC is followed by a few command switches
TOC [Switches ]
These switches determine what's included in the table of contents. You can find a full list of these from the following Microsoft support page.
Field codes: TOC (Table of Contents) field
Windward only supports a subset of the switches that Word supports. We do not support "\z" and "\u", however, for DOCX output, we copy everything across so they are “supported” for DOCX output. When using a TOC in a Windward template please only use our supported switches shown below.
The TOC page numbers in a DOCX file will be the same as in the PDF and that usually will not match the actual page number in DOCX this is a known limitation.
\p "Separator"
Specifies the character that separates an entry and its page number. For example, the field { TOC \p "—" }, with an em dash, displays a result such as "Selecting Text—53." The default is a tab with leader dots. Just one character is allowed; it must be enclosed in quotation marks.
\h Hyperlinks
Inserts TOC entries as hyperlinks.
\l Levels
Builds a table of contents from TC fields that assign entries to one of the specified levels. For example, { TOC \l 1-4 } builds a table of contents from TC fields that assign entries to levels 1-4. TC fields that assign entries to lower levels are skipped.
\o "Levels"
Builds a table of contents from paragraphs formatted with styles that include outline levels (most commonly, heading styles). For example, { TOC \o "1-3" } lists only paragraphs formatted with styles that include outline levels 1 through 3. If no range of outline levels is specified, all outline levels used in the document are listed. Enclose the range numbers in quotation marks.
Any other switches simply will not generate as expected. Given the switches used above the output of our sample template looks like the following in both DOCX and PDF Output:
DOCX Output:
PDF Output: