This template generates an appropriate {{TOC link}} template for a page number when supplied with parameters for a particular work. It is intended to automate the process of creating page links when a large number are required (normally in a book index).

In particular, this template automates the process of setting the scan page link and the chapter title, which would otherwise need to be done manually for every instance of {{TOC link}}. Because it uses an offset for the page number and a single switch to determine the correct chapter, {{Auto TOC link}} can be substituted in for every page number by a simple regex query.

Usage edit

To use this template in a particular work, a subpage of the template needs to be created containing a function that will return the appropriate subpage of the work for a given page number, e.g.:

{{#switch: 1
| {{#expr: {{{1|}}} < 5}} = Chapter 1
| {{#expr: {{{1|}}} < 15}} = Chapter 2
| {{#expr: {{{1|}}} < 25}} = Chapter 3
| {{#expr: {{{1|}}} < 50}} = Chapter 4
}}

Three parameters are required:

  • 1: The page number
  • 2: The offset of the corresponding page in the Page namespace, e.g. 3 if page 1 is located at Page:…/4
  • 3: The title of the relevant subpage of this template.

Example edit

{{Auto TOC link|55|18|EinC}}55

{{Auto TOC link/EinC}} contains a switch that will return the correct chapter for a given page number in Europe in China. Page 55 is in Chapter 6 of the work, so on this page the template links to Template:Auto TOC link/Chapter 6#55.

See also edit

  • {{TOC link}}: for table of content page links, allowing linking to mainspace chapter
  • {{Scan page link}}: for auto-offset page links
  • {{Scan page link 2}}: for page links that cannot be auto-offset (e.g. roman numerals)
  • {{Scan page link 3}}: for page links that are not auto-offset, and allow linking to mainspace chapter
  • {{Double link}}: for any link that varies when in Page: and the mainspace
  • {{Namespace link}}: for links that vary between any namespaces