# Page Toc Plugin (Anchors + Table of Contents) The **Page Toc** Plugin is for [Grav CMS](http://github.com/getgrav/grav) that generates anchors based on HTML header tags, and can also create a table of contents from those headers. With version `3.0` this plugin is able to automatically generate anchor links with hover-click capability without the need for other plugins (such as the `anchors` plugin). This functionality operates independently from the now optional "table of contents" functionality. ![](assets/page-toc.png) ## Installation Installing the Page Toc plugin can be done in one of two ways. The GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file. ### GPM Installation (Preferred) The simplest way to install this plugin is via the [Grav Package Manager (GPM)](http://learn.getgrav.org/advanced/grav-gpm) through your system's terminal (also called the command line). From the root of your Grav install type: bin/gpm install page-toc This will install the Page Toc plugin into your `/user/plugins` directory within Grav. Its files can be found under `/your/site/grav/user/plugins/page-toc`. ### Manual Installation To install this plugin, just download the zip version of this repository and unzip it under `/your/site/grav/user/plugins`. Then, rename the folder to `page-toc`. You can find these files on [GitHub](https://github.com/team-grav/grav-plugin-page-toc) or via [GetGrav.org](http://getgrav.org/downloads/plugins#extras). You should now have all the plugin files under /your/site/grav/user/plugins/page-toc ## Configuration Before configuring this plugin, you should copy the `user/plugins/page-toc/page-toc.yaml` to `user/config/plugins/page-toc.yaml` and only edit that copy. Here is the default configuration and an explanation of available options: ```yaml enabled: true # Plugin enabled include_css: true # Include CSS active: true # Anchor IDs processed and generated for all pages start: 1 # Start header tag level (1 = h1) for TOC depth: 6 # Depth from start (2 = 2 levels deep) for TOC hclass: # Custom Header TOC styling classes anchors: # Anchor configuration start: 1 # Start header tag level (1 = h1) depth: 6 # Depth from start (2 = 2 levels deep) link: true # Enabled auto-generation of clickable link with fragment aria: Anchor # Aria label to use class: # Custom Header anchor styling classes icon: '#' # Icon to use, can be a symbol, emoji, ascii etc. position: after # Position to put the anchor, `before|after` copy_to_clipboard: true # Copy to clipboard functionality (coming soon) slug_maxlen: 25 # Max length of slugs used for anchors slug_prefix: # A prefix used in front of generated slugs ``` > You can now have `page-toc` automatically add anchors without there being a table of contents being used, just ensure `active` to `true`. By default, The plugin is `active` and will add header id attributes anchors for each header level found in a page. You can set `active: false` and then activate on a page basis by adding this to the page frontmatter: ```yaml page-toc: active: true ``` You can also configure which header tags to start and depth on when building the id attribute anchors by changing the `start` and `depth` values. This can also be done on a per-page basis. For example if you had a start of `3` and a depth of `3` you would get a TOC for `h3`, `h4`, and `h5`. ## Usage ### Shortcode-like syntax in your content You can use the following shortcode-like syntax in your content: ```md [TOC] or [TOC/] or [toc] or [toc /] ``` This will replace the shortcode syntax with the Table of Contents with the `components/page-toc.html.twig` Twig template. Either the default one included in the `page-toc` plugin or an overridden version from your theme. For example in Quark theme, you will need to create a folder called `components/` under `templates/` so the file will be copied to: ```shell user/themes/quark/templates/components/page-toc.html.twig ``` NOTE: It's not required to set the TOC plugin `active` if you use the shortcode syntax in your content. That is a good enough indication that you want the plugin to be active. ### Customizing specific anchors There are situations where you want to have absolute control over the exact anchor link rather than letting page-toc create one for you. The best way to achieve this is to add your own `id` attribute to the header tag. This can be done either via HTML in your markdown directly: ```html