mortenhagh
(Morten Jensen)
June 15, 2021, 7:45pm
1
I am trying to figure out how I can make a TOC (Table Of Contents) in NUXT from all the headers in a slice zone.
If I am building a page with for example 4 paragraphs each with a H2 header and some H3 headers I want to take out all those headers from the slice zone and then build the TOC.
Does anyone have a good approach to this?
Phil
(Phil Snow)
June 16, 2021, 10:56am
3
Hi Morten,
Welcome to the community!
I actually explain how to do that in Vue/Nuxt on this post here:
Hey @jerry.nummi ,
For your use case of the sub navigation. Something I do is use the HTMLSerializer to automatically add id's to my H2's from my rich texts. Like I do here:
if (type === Elements.heading2) {
var id = element.text.replace(/\W+/g, '-').toLowerCase();
return '<h2 id="' + id + '">' + children.join('') + '</h2>';
}
Then I build a component that looks at the Slices on the current page, takes any H2 titles and creates a link to these. This example is in Vue, but you can eā¦
Let me know if you have any questions about this.
Thanks.
mortenhagh
(Morten Jensen)
June 16, 2021, 8:13pm
4
That works perfectly! Thanks!
1 Like
system
(system)
closed as resolved, flag & select 'Something Else' to reopen.
June 17, 2021, 8:14pm
5
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.