Table of Contents

Is it possible to have the Table of Contents wrapper be conditional based on whether there are any Heading elements in inside of the “Contents”?

I am adding the Table of Contents to a Template page, and sometimes the “Content” rich text field has Heading elements present and sometimes it does not. When there are no Heading elements the TOC wrapper and initial “Example H2” link still show.

Thank you,

Hey @edrock! I’m afraid there is no such functionality at the moment, however, you can always simulate an H2 with the setting option below to avoid the “Example H2” from showing.

Thank you Luis!

I ended up using this as a quick work-around.

    function hideTocTableIfNoHeadings() {
        const richText = document.querySelector('.rich-text');
        const headings = richText.querySelectorAll('h1, h2, h3, h4, h5, h6');
        const tocTable = document.querySelector('[fs-toc-element="table"]');
        if (headings.length === 0) {
   = 'none';
1 Like