Problem/Motivation
Surprised this isn't already part of this module but figured easy enough to create. Unfortunately i started by extending the existing TocBlockBase; which has errors with all of the classes it is implementing; so that was a bad place to start.
After i simply extended the core BlockBase this seemed to work. Going from the _view hook code in the README i see i can pass TOC and/or a modified version of my content (used to create the TOC).
This raises questions:
- of course i don't want to add a TOC block with my rewritten content into the layout of my content; then i end up with 2 copies of my content.
- but if i remove adding the content, the anchor links in the TOC don't go anywhere.
How is this expected to be done?
I see 2 options:
1. I need a fake duplicate view mode which is used to simply create the TOC and then the TOC block is placed in the real full_content view mode without any of the content used in the fake one. I am sure this will become problematic as the layout becomes more complex. Not to mention it is redundant.
2. seems like far more reasonable - i write extra js to addin anchor IDs to all the heading tags.
Option 2 sounds promising but wondering why that isn't at least an option here.
Comments
Comment #2
liquidcms commentedIn case anyone comes looking for this, i wrote Block code to allow placing a TOC block. It also uses JQ to go through the page headings and add IDs to them so that the anchor links work.
and JS for only h2/h3 (could be done recursively)
Comment #3
joseph.olstadPlease note, 1.x is no longer supported
All MRs should now be reviewed and made to go against 2.0.x if still needed
Comment #4
joseph.olstadNot sure if this helps but there is a contrib module implementing the toc_api
The module is called Toc Twig Filter
#3521657: Contrib Modules using TOC API
Comment #5
joseph.olstadalso, the footnotes module
https://www.drupal.org/project/footnotes
which actually implements the toc_filter module more specifically , it's the toc_filter module which directly implements the toc_api module.
Comment #6
joseph.olstadGood example @liquidcms, this could go into the module README.md or documentation page.
Comment #8
joseph.olstadPut this into our README.md
Comment #11
joseph.olstadhttps://git.drupalcode.org/project/toc_api/-/blob/2.0.x/README.md
Comment #13
joseph.olstadhttps://www.drupal.org/project/toc_api/releases/2.0.1-rc1