Jump to content

Recommended Posts

Posted

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!

Posted

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 :(

Posted
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 :)....

 

  • Like 2
  • 3 years later...
Posted
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.

  • Like 1
Posted

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>";
}

 

  • Like 1
  • Thanks 1
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...