OllieMackJames Posted February 1, 2017 Share Posted February 1, 2017 SOLVED: easiest way is to use the HannaCode example from @ryan as mentioned here: https://processwire.com/modules/process-hanna-code/#jumplinks-hanna-code-example-for-import I am trying to get a Table of content that will display - wikipedia style - all different headers on one page in a table. I need the TOC to automatically run down the page and pick the H2, H3 and H4 headers and put them in the TOC, with the link to those headers right in the TOC. Anybody know how to do this? Thnks! Link to comment Share on other sites More sharing options...
Robin S Posted February 1, 2017 Share Posted February 1, 2017 A similar topic with some solutions: 1 Link to comment Share on other sites More sharing options...
mr-fan Posted February 1, 2017 Share Posted February 1, 2017 Quote Anybody know how to do this? I would have googled it...;) http://stackoverflow.com/questions/15628305/creating-a-table-of-contents-in-php http://www.10stripe.com/articles/automatically-generate-table-of-contents-php.php https://css-tricks.com/automatic-table-of-contents/ https://www.princexml.com/forum/topic/1200/generating-a-toc-with-php regards mr-fan 2 Link to comment Share on other sites More sharing options...
SiNNuT Posted February 1, 2017 Share Posted February 1, 2017 I could have sworn that i've once seen something like this floating around the forum. I think it was a textformatter that autmates toc and is used on the PW sites for blog posts and such. Can't find it though Link to comment Share on other sites More sharing options...
tpr Posted February 1, 2017 Share Posted February 1, 2017 Well if a jQuery solution is OK to you here's one. 2 Link to comment Share on other sites More sharing options...
kongondo Posted February 1, 2017 Share Posted February 1, 2017 29 minutes ago, SiNNuT said: I could have sworn that i've once seen something like this floating around the forum. I think it was a textformatter that autmates toc and is used on the PW sites for blog posts and such. Can't find it though There's this one...which you contributed to .... 2 Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted December 16, 2020 Share Posted December 16, 2020 On 2/1/2017 at 10:26 PM, SiNNuT said: I could have sworn that i've once seen something like this floating around the forum. I think it was a textformatter that autmates toc and is used on the PW sites for blog posts and such. Can't find it though Was looking for this too) I guess this is it. Hope it will help someone as this topic is #1 result for the search "textformatter toc". Found the link with some nice extra content here. 1 Link to comment Share on other sites More sharing options...
flydev Posted December 17, 2020 Share Posted December 17, 2020 Thanks @Ivan Gretsky I will look at this and for sure update my code snippet : use PHPHtmlParser\Dom; function print_toc($html, $link = '', $depth = 1) { $dom = new Dom; $dom->loadStr($html); $headings = $dom->find('h'. $depth); $toc = ''; foreach ($headings as $h) { $name = wire('sanitizer')->pageName($h->text); $name = strtolower($name); if($name) $toc .= "<li><a href='{$link}#{$name}'>$h->text</a>"; } return "<ul>$toc</ul>"; } 1 1 Link to comment Share on other sites More sharing options...
Recommended Posts