3

In MediaWiki, we would like to display tables of contents (from multiple pages) on one other page. We know that this can be done automatically, e.g. if we include pages 1, 2 & 3 like this:

{{:Page 1}}
{{:Page 2}}
{{:Page 3}}

on page X, then page X displays a combined TOC for pages 1, 2 & 3.

But we want a table on page X which shows each TOC in a separate cell. Is there any way to include each TOC individually?

I have tried using <noinclude></noinclude> tags around the text on pages 1, 2 & 3 and then forcing a table of contents outside (using __TOC__) but that only creates a TOC on page X (using the contents of page X).

1 Answers1

2

You can't. The table of contents is generated dynamically in each page, for all the sections that appear in the current page.

When you include the sections (or at least the section headings) of the other pages, they will show up in the TOC of page X. If you include the __TOC__ magic word, it means only to generate the toc for page X.

Three solutions:

  1. Include the section (headings) of pages 1, 2 and 3. They will show up in the toc of page X even when contained in a <div style="display:none;"> - a really ugly way.
  2. Copy the TOC tables manually to page X. You can view their HTML by looking in the generated HTML source of pages 1, 2 and 3 with your browser.
  3. Write an extension that allows transclusion of TOCs from other pages. It might introduce a new parserfunction {{toc:<pagename>}} and be able to call the toc-generating function in the context of another page.
  4. Include only the section headings as a list. In the pages 1, 2 and 3 you will need to write

    == <onlyinclude><includeonly>##</includeonly> Heading Number One </onlyinclude> ==
    === <onlyinclude><includeonly>###</includeonly> Part One of Heading Number One </onlyinclude> ===
    ...
    

    which you will be able to include in the table at Page X with

    {{:Page 1}}
    

    It should show up as a numbered list, like the TOC.

svick
  • 236,525
  • 50
  • 385
  • 514
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • Solution #1 works really well, thanks. However, I should have mentioned that really there are multiple Page Xes: X1, X2, X3, ... that all have to fit into a table on Page Y (one "X" per cell). I think my question was not clear on that. Any ideas? – Reinstate Monica - Goodbye SE May 14 '12 at 12:52
  • Yes, #1 is not really a solution. Extended answer. – Bergi May 14 '12 at 13:01
  • I think actually Page 1 should be `== Header == ` and Page X should be `{{:Page 1}}` (where `` is literally a new line; note also the semi-colon on Page X. This works for Page X1, X2, etc. but not for Page Y containing each Page X. – Reinstate Monica - Goodbye SE May 14 '12 at 13:24
  • Na, you don't wont to transclude section headings, do you? I think you only want their titles. – Bergi May 14 '12 at 14:05
  • Right - but when I use your solution, nothing appears on Page X. Page X (in my version) contains `
    {{:Page 1}} {{:Page 2}} {{:Page 3}}
    ` - each item on a new line.
    – Reinstate Monica - Goodbye SE May 14 '12 at 14:12
  • The first solution (where the hidden sections should show up in the `__TOC__`) is different from solution #4, where the section names are transcluded as a numbered list. – Bergi May 14 '12 at 14:22
  • Solution #1 works, #4 just includes `Heading Number One ### Part One of Heading Number One` in a numbered list - no titles, no TOC. Problem is, #1 still lumps everything together into one TOC. – Reinstate Monica - Goodbye SE May 14 '12 at 15:02