Expand/Collapse based on number of Section Blocks

Topic summary

A user is building a custom section that displays multiple content blocks and wants to implement show/hide functionality:

Goal:

  • Display the first 6 content blocks by default
  • Hide any blocks beyond 6 behind a “Show More/Show Less” toggle button

Current Status:

  • Found an example script but cannot get it to work properly
  • For testing purposes, set the threshold to 4 blocks instead of 6
  • Included simplified markup and JavaScript code examples

Issue:
The collapse/expand functionality is not working as intended despite attempts to adapt existing code. The discussion remains open with no solutions provided yet.

Summarized with AI on November 4. AI used: claude-sonnet-4-5-20250929.

I have created a new section where I am adding multiple content blocks but have run into an issue that I am hoping for some help with.

I’d like to add functionality where the first 6 content blocks are added to the page and anything over 6 gets put behind a Show More/ Show Less button to expand & collapse the content.

For ease, I’ve simplified the content that gets written just to show as an example.


I saw an example of a script that I just can’t get to work properly. In this case, I just have the size integer sset to 4 to try and force it on my dummy content.


Any help would be appreciated.