Help with Table of Contents - hiding/showing table of contents depending on length

Can anyone help?

What I want to do is generate a table of contents and if it’s longer than 5 items, hide items 6+ behind an accordion. How could I achieve this?

Hey @merinostudio! There is no native way to do this but you can use custom code with the Attributes API to run code after Table of Contents has successfully loaded with this callback

<script>
  window.fsAttributes = window.fsAttributes || [];
  window.fsAttributes.push([
    'toc',
    (tableInstances) => {
      console.log('table of contents Successfully loaded!');

      // Add custom code here!
    },
  ]);
</script>