Manual talk:Table of contents

CSS To Change Numbering for the ToC
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-image:none; list-style-position:inside; list-style-type:armenian /*replace this with the type of number you want*/; }

span.tocnumber { display:none; } Bawolff (talk) 03:11, 16 April 2012 (UTC)

Auto-collapse TOC on a given page?
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
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: http://en.wikibooks.org/wiki/MediaWiki_User_Guide/Sections_and_Headings#Headings_not_in_TOC --Albert25 (talk) 12:32, 13 June 2013 (UTC)

Permanently repositioning the ToC directly after the title?
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, 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)

Solution
This is hard-code solution, if you find extension solution, please mention it. This will force to place TOC at the beginning of all documents
 * 1) Go to includes/parser/Parser.php
 * 2) Find doDoubleUnderscore method
 * 3) Add the following line at the beginning of the method
 * $text = "" . $text;

Is there a way to Apply Multilingualism to Contents Label in the TOC Template or Even Custom Title?
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
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 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
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'); toc.style.display = 'none'; } hideToc;

Improved Solution
This is working for me on 1.34.0:

var toc, toggleLink; try { toc = document.getElementById('toc').getElementsByTagName('ul')[0]; toggleLink = document.getElementById('toctogglecheckbox'); // if (tocIsHidden) { toggleToc; // } } catch (error) { console.log('erred', error); } function tocIsHidden { return !toc || !toggleLink || window.getComputedStyle(toc).display !== 'block'; }

function toggleToc { var hidden = tocIsHidden; if (hidden && document.cookie.indexOf('hidetoc=0') > -1) { toggleLink.click; // changeText(toggleLink, tocShowText); // toc.style.display = 'none'; } else if (!hidden && document.cookie.indexOf('hidetoc=1') > -1) { toggleLink.click; // changeText(toggleLink, tocHideText); // toc.style.display = 'block'; } } toggleLink && toggleLink.addEventListener('click', function {  var isHidden = tocIsHidden;  document.cookie = isHidden    ? "hidetoc=1"    : "hidetoc=0"; });


 * I have some problems with the "quick an dirty" [sic] technique shown above:
 * It doesn't always work. When the code executes, the page may not have been fully loaded or parsed.  Therefore, the element with the   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.)
 * When the code hides the TOC, it doesn't change the "hide" link text to "show". That looks bad.
 * The  variable is never used. Getting that element wastes time.
 * A better solution would:
 * Wait until until after the page has been loaded and parsed by the web browser before trying to hide the TOC.
 * Use the  JavaScript function provided by MediaWiki to:
 * Hide or show the TOC as necessary.
 * Change the "hide" link text to "show" or vice versa.
 * Set a  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  page:
 * Change the "hide" link text to "show" or vice versa.
 * Set a  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  page:
 * Add the following JavaScript code to your wiki's  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.      toggleToc;    }  } 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  page.  For documentation about enabling this feature, see the following manual pages:
 * Manual:Interface/JavaScript
 * Manual:$wgUseSiteJs
 * --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   is loaded and that the above-proposed code is executed, but I keep getting a   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.
Manual:Table of contents refers to MediaWiki:Common.css in order to find the relevant  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?
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 14.207.179.110 (talk • contribs) 05:39, 23 May 2017‎

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