Dynamically Populate Section ID on Collection Items

Hey guys – Hope you can help me out here.

I’m trying to dynamically populate the section ID of a Rich Text element based on the main header on that element. So ideally i’d look like this:

I want to do this so i can create unique on-page links for readers to navigate the article (this is for a blog).

I’ve tried following this guide, but it didn’t work for me.

I guess I need to use custom code to accomplish this, but any suggestions on how to do it?

Thanks!!