Table of Contents Generator

Filters ::: filter_toc
Maintained by Ben Chenoweth
Automatically generated table of contents for a page of content.
Latest release:
58 sites
24 downloads
11 fans
Current versions available: 1

Table of Contents (TOC) Filter

2017 version


The Table of Contents filter scans pages for heading tags (like h1, h2, etc) and automatically generates a nested list of these tags as a table of contents. Each entry in the table is made into an html link to the actual heading.

The plugin has both global and local settings.


Global Settings

  • Headings: you can nominate which headings tags you want the filter to look for (default: h1,h2,h3,h4)
  • Search in divs: you can choose whether or not to look for headings tags located inside divs (default: yes)
  • Backlink: you can choose whether or not to include a backlink at the end of the heading that links back to the TOC.
  • TOC Title: you can nominate the title used in the TOC (default: Table of Contents)
  • TOC Title Heading Tag: you can choose which heading tag is used for the TOC's title (default: 1)


Local Settings

(The local settings allow you to override the global settings on a per page basis.)

  • Headings: you can nominate which headings tags you want the filter to look for
  • TOC Title: you can nominate the title used in the TOC
  • TOC Title Heading Tag: you can choose which heading tag is used for the TOC's title


Hiding Individual Headings

You can also hide specific headings from the TOC by wrapping the heading in a div with class="non-toc".  For example,

<div class="non-toc">
<h1>Lesson 1 — Greco-Roman Civilisation</h1>
</div>


Location

By default, the location of the TOC is placed at the beginning of the page. However, you can nominate a different position by putting the string

[contents]

where you want the TOC to appear.


CSS

CSS styling may be used to modify the appearance of the table. The entire table is contained within a div with the 'toc' class. The backlinks have the class 'toc_link' applied to them.  For example,

/* Hide bullets in TOCs */
.toc ul {
    list-style: none;
}

(Add to the custom CSS field of your moodle theme.)

Screenshots

Screenshot #0
Screenshot #1
Screenshot #2
Screenshot #3
Screenshot #4
Screenshot #5

Contributors

Ben Chenoweth (Lead maintainer)
Nigel Cunningham: Original author
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • David Mudrák
    Fri, 29 Sept 2017, 7:23 PM

    I am happy to announce that Ben Chenoweth became a new maintainer of this plugin and hopefully will be able to release an update for more recent Moodle versions soon. Good luck Ben, and thanks for your offer to maintain this!

  • Sa Ku
    Mon, 19 Nov 2018, 1:29 PM
    How to change the location of the TOC? For instance, I would like to add this to the Right side block and as a floating one.
  • Ben Chenoweth
    Mon, 19 Nov 2018, 2:39 PM
    Sa Ku, that's an interesting suggestion, but it is not currently possible at the moment. The only customisation regarding placement of the TOC is to put

    [contents]

    where you want the TOC to appear on the page itself.
  • Sa Ku
    Mon, 19 Nov 2018, 4:34 PM
    @Ben: Thanks for your reply. Can you please help me understand is how and where to update the [contents] and how to modify the CSS of the TOC?
  • Sa Ku
    Mon, 19 Nov 2018, 4:38 PM
    Also, when I remove h4 from the settings, the entire TOC disappears from the topic. This happens when I try to make changes to global and local settings. Is that a known bug?
  • Ben Chenoweth
    Tue, 20 Nov 2018, 8:35 AM
    The instructions for modifying the CSS are given above. You have to add to your custom CSS, using the .toc class. For example,

    /* Hide bullets in TOCs */
    .toc ul {
    list-style: none;
    }

    There are no bugs that I am aware. My only guess is that all of the headings on your page are h4 headings. So when you remove h4 from the settings, there are no headings left to generate a TOC.
  • Tim Tarbotton
    Sat, 2 May 2020, 10:32 AM
    Hi there, i have installed your plugin and its enabled. I was expecting this TOC to appear at the top of my course pages but I can't seem to see it? I am not a developer but wondered how exactly do you add [contents] to the top of the page? I definitely have a range of h1 h2 h3 h4 text on the course page. Is there somewhere in the Moodle course menu or site admin I can do this? Or do I add it within an activity? Sorry if this is a silly question, It may be beyond my depth of knowledge. Appreciate the help. Tim
  • Ben Chenoweth
    Sat, 2 May 2020, 10:48 AM
    It's been a while since I've worked on a Moodle site. My recollection is that if the plugin is enabled, the TOC appears at the top of a page automatically. You only have the add [contents] if you want the TOC to appear elsewhere. The TOC is generated using a Moodle filter, so look for the plugin to appear in the list of filters for a specific page.
  • Tim Tarbotton
    Sat, 2 May 2020, 10:55 AM
    Hi Ben, thanks for the reply. On the course page I can see the "Table of Contents Generator" under Course Administration > Filters and this is turned on which is why I thought I had to add [contents] as it does not show the TOC at the top of my course page as expected? My course pages are default Moodle pages (nothing fancy) so perhaps there could be a bug with my version of Moodle? I believe i am on Moodle 3.4.2+ (Build: 20180421) - Once again, thanks for the response. Tim
  • Ben Chenoweth
    Sat, 2 May 2020, 11:03 AM
    The TOC won't appear on the course outline, just on the individual pages.
  • Ben Chenoweth
    Sat, 2 May 2020, 12:18 PM
    Yes, it won't appear here, because this is the course homepage. The TOC filter only applies to in-course content pages.
  • Zabelle Motte
    Thu, 8 Apr 2021, 12:11 AM
    Great thanks fot this plugin that helps us to make documentation pages with table of content.
    We have one suggestion for that plugin.
    As far as we use a custom theme, we need to style the "a" tags that support the table of content, so that vertical alignment is correct.
    It would be great to a a specific class on "a" tags added in filter.php line (lines 78 et 80).

    Kisses

    Zabelle
  • Ben Chenoweth
    Thu, 8 Apr 2021, 3:52 PM
    Hi Zabelle,
    Sorry, but I am no longer able to support this plugin. I am not currently working at a place that uses Moodle, so I cannot do the required testing of any changes made to the code. The code itself is located at https://github.com/benchen71/moodle-filter_toc.
  • Zabelle Motte
    Fri, 31 Mar 2023, 8:17 PM
    I proposed a patch that seems to make this plugin work on Moodle 4, but do not hesitate to test and to comment.
    https://github.com/benchen71/moodle-filter_toc/issues/5
  • S G
    Sun, 4 June 2023, 8:13 PM
    @Zabelle Motte
    Thank you for the patch.

    Installed and tested on Moodle 4.1.3+ (Build: 20230602)

    It is working as expected. Will update here and on Github if I see any issues.
1 2
Please login to post comments