2019.2

Table Of Contents
Step 1: Opening a Print template
Create or open a Print template.
Make sure to use HTML headings level 1 and level 2 (<h1> and <h2>) in your Print sections, if
you want to use the script sample that is given in Step 3.This script collects the text and page
numbers of these headings and puts them in the TOC.
To quickly change a paragraph into a Heading, place the cursor inside of it, or select the
paragraph (see: "Selecting an element" on page195). Then select the appropriate element,
either on the Format menu, or from the 'Element type' drop-down on the toolbar.
Of course, you could just as well create a table of contents using other heading levels, or even
other elements. In that case you'll have to adjust the script accordingly.
Step 2: Creating a placeholder for the TOC
Create one extra Print section to put the Table Of Contents in.
Inside the extra section, insert an Article element (see "Inserting an element" on page194).
Give the element an ID, for example: toc-content. This element is the placeholder for the TOC.
Step 3: Inserting the Post Pagination script
Insert a Post Pagination script (see "Adding a Post Pagination Script" on the previous page).
Double-click on the new script to open it.
Set its selector to the ID that you specified in Step 2, preceded by a #, for example: #toc-
content.
Paste the following code in the script editor:
// Build the TOC
var toc = '';
merge.context.query("h1, h2").each(function() {
var pageNo = this.info().pageNo;
var text = this.text();
var level = this.tagName();
toc += '<p class="toc-entry ' + level + '">';
toc += '<span class="text">' + text + '</span>';
toc += '<span class="dots"></span>';
toc += '<span class="number">' + pageNo + '</span></p>';
});
results.html( toc );
// Repaginate the result
Page 429