Manual talk:Table of contents

Jump to navigation Jump to search

CSS To Change Numbering for the ToC[edit]

Stashing here for later reference. CSS i was playing with to change the numbering scheme on the ToC:

html #toc ul, .toc ul {
list-style-type:armenian /*replace this with the type of number you want*/;

span.tocnumber {

Bawolff (talk) 03:11, 16 April 2012 (UTC)

Auto-collapse TOC on a given page?[edit]

Question - is there a way to auto-collapse the TOC on a given page? NOTOC gets rid of it, but I just want it collapsed, with the reader able to show it again should they wish. Manning Bartlett (talk) 04:08, 13 March 2013 (UTC)

Yes! Under the "Collapse (Hide) TOCs When Pages Load" section below, see the "Improved Solution" section. It collapses TOCs on all pages in the wiki, though, not for a specific given page. --Lance E Sloan 21:13, 31 August 2017 (UTC)

NOTOC for selected headers[edit]

Here my question, I want to have the Table of Contents in the page, but there are one header & subheaders that I don't want to show in it. Is that possible?

I show and example:

 = Show 1 = 
 == Show 1.1 == 
 === Show 1.1.1 === 
 == Show 1.2 == 
 = Hide 2 = 
 == Hide 2.1 == 
 === Hide 2.1.1 === 
 = Show 3 = 

I hope that be clear that I mean.

There is no easy way: --Albert25 (talk) 12:32, 13 June 2013 (UTC)

Permanently repositioning the ToC directly after the title?[edit]

I cannot figure out how to permanently move the position of the Table of Contents. I have changed the CSS to float the ToC left, but I need it to come directly after the H1 heading on the page, rather than before the first H2 heading, for the text to wrap how I want it to. I can accomplish this with __TOC__, but doing this on every single page is infeasible. I have not found an extension that does this either.

My question is: how would I even begin to change that? Would a skin do it? I've looked through my skin, I've looked through all the skinning manuals I can find, I even looked through SkinTemplate.php and Skin.php in the MediaWiki files, but I can't figure out which file it is -- if there even is a single file -- that simply lays out the order the different elements appear in the page code. There are a ton of variables and hooks and arrays that I suspect this is buried in, and I only have moderate programming ability so I can't dig it up on my own. It would generally be helpful to know where I'd go if I wanted to add something like a containing div around things like the ToC. Natrashafierce (talk) 20:23, 23 August 2014 (UTC)

I'm trying to so something similar. Cant find the answer for the life of me.
Vapblack (talk) 13:53, 12 December 2014 (UTC)

Is there a way to Apply Multilingualism to Contents Label in the TOC Template or Even Custom Title?[edit]

For example, is there a way to have the header within the TOC modified to match the applicable language if an individual selects the other language page under the navigation menu (left side) and it automatically modifies the applicable language setting, as well (top right) with that click rather than an individual having to change the language setting in top right as an additional steps? As example text, the header text would be Contents in English and Sommaire in French. Thanks!

Quadra23 (talk) 17:02, 20 January 2015 (UTC)

Header numbers but no titles[edit]

The strangest thing... I have an instance running that produces a TOC of just nested numbers, without the associated titles. The syntax of the sections hasn't changes (since when it used to work). If I poke into the html, I can see <a name> anchor tags that are blank or have "_#". So, I suspect something in MediaWiki text parser if failing to properly turn my section headers into anchors that TOC depends on.

Any hints as to how to track this bug down?

Collapse (Hide) TOCs When Pages Load[edit]

An quick an dirty way to have the TOC start collapsed

Open MediaWiki:Common.js

Add this to the js

//collaps default the TOC on opening an pages 
function hideToc() { 
  var toc = document.getElementById('toc').getElementsByTagName('ul')[0]; 
  var toggleLink = document.getElementById('togglelink'); = 'none'; 

Improved Solution[edit]

This solution, no longer works since MediaWiki 1.29
I have some problems with the "quick an dirty" [sic] technique shown above:
  1. It doesn't always work. When the code executes, the page may not have been fully loaded or parsed. Therefore, the element with the toc ID may not be available and the code will fail. (When code is added to make it wait for the page to load and be parsed, then it works to some degree.)
  2. When the code hides the TOC, it doesn't change the "hide" link text to "show". That looks bad.
  3. The toggleLink variable is never used. Getting that element wastes time.
A better solution would:
  1. Wait until until after the page has been loaded and parsed by the web browser before trying to hide the TOC.
  2. Use the toggleToc() JavaScript function provided by MediaWiki to:
    1. Hide or show the TOC as necessary.
    2. Change the "hide" link text to "show" or vice versa.
    3. Set a hidetoc cookie in the web browser to indicate whether the TOC should be hidden or shown the next time a page is loaded from this wiki.
Add the following JavaScript code to your wiki's MediaWiki:Common.js page:
// The enclosed code runs only after the page has been loaded and parsed.
window.addEventListener('DOMContentLoaded', function() {
  try {
    // Detect whether the page's TOC is being displayed.
    if (document.getElementById('toc').getElementsByTagName('ul')[0].style.display != 'none') {
      // Use MW's toggleToc() to hide TOC, change "hide/show" link text, and set cookie.
  } catch (exception) {
    // Probably this page doesn't have a TOC, ignore the exception to prevent console clutter.
}, false);
Or use this shorter version without comments:
window.addEventListener('DOMContentLoaded', function() { try {
  if (document.getElementById('toc').getElementsByTagName('ul')[0].style.display != 'none') { toggleToc(); }
} catch (exception) {} }, false);
Remember: By default, MediaWiki will not use the JavaScript in your wiki's MediaWiki:Common.js page. For documentation about enabling this feature, see the following manual pages:
--Lance E Sloan 21:07, 31 August 2017 (UTC)
I am trying to implement this solution on a MediWiki site I admin. I checked that MediaWiki:Common.js is loaded and that the above-proposed code is executed, but I keep getting a ReferenceError: toggleToc is not defined error. Any idea why this is happening and how to solve it? Thanks in advance for any help you might provide Lucamauri (talk) 12:53, 18 February 2018 (UTC)

Relevent CSS rules for TOC depth.[edit]

Manual:Table of contents#Depth refers to MediaWiki:Common.css in order to find the relevant toclimit-<limit> styles, but it appears as though Common.css is just empty. I'm not sure if this is a result of most of the styles being moved into a default location and that file just being used for overrides or something. I'm not sure where to go about finding these.

Can I add Table of Content of one page to another page?[edit]

I want to make an index page that always show table of contents of another pages. I want it to always sync and don't need to update it manually. Is it possible? — Preceding unsigned comment added by (talkcontribs) 05:39, 23 May 2017‎

Still show a little TOC button when __NOTOC__ is used[edit]

IDEA: when __NOTOC__ is used, a little [TOC} etc. or whatever tiny marker should still show up, that the user can push, revealing the Table of contents. Jidanni (talk) 12:28, 12 December 2017 (UTC)