Modular page anchor link field

I’m looking for some advice on how people handle this situation - I’ve got some modular pages that I want to create anchor links to from other pages on the site. How do you create the links?

I’ve been using the slug field and adding {{ page.slug }} to my templates. This works but slug url isn’t ideal for a number of reasons, one of which is the url itself starts with a _ which isn’t really user friendly.

So how are other people doing this - custom field, js/php script, something else?


I did this some time ago and didn’t end up using it, so had to dig to find it. Sorry it took so long.

To create the anchor links in the template, I used an id property in the modular frontmatter. So custom field, yes.

I set in my modular template like this:

<ul id="{{}}" class="teasers profiles">

When I had a tabbed display on the parent of the modular pages (landing/index page), I also wanted the option to link to specific tabs from the menu. Basically, I had fragment links in my menu. I didn’t end up doing that anyway, but here’s what my navigation.html.twig partial template looked like, and I think it worked. For the modular pages I wanted visible in the menu, I just set a visible property in the frontmatter and queried that. Modulars are not visible by default.

Hope that helps if not too late.

1 Like

Hi @hughbris I was hoping for some built in field I missed for the id but I guess custom field is the most flexible. Thanks for taking a look.