سؤال

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).

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top