Adding anchors to in-editor page links

Enonic version: 4.7.11
OS: OS X / Linux

When creating custom content in an htmlarea input field, I want to create a link to another page. These are the steps needed to reproduce:

  • Mark some text and create a link
  • Choose type: page and select a page to link to
  • Set Anchor to the ID I want to scroll to on the page I am linking to
  • Save the link. The HTML now shows <a href="page://12406#my-anchor-tag">Testlink</a>

When I publish this, the href reads [undefined]: Invalid MenuItemKey: 12406#my-anchor-tag.

Removing the anchor fixes the problem. This leads me to conclude that you try to look up the menu item key 12406#my-anchor-tag, instead of 12406, and then appending #my-anchor-tag, which I would assume is the expected behavior.

Another related “bug” - or weakness, perhaps - is that if you start your anchor with a hashtag (#), you get two hashtags. I suggest you add a check for this.

Best regards,

Kristofer Selbekk

Thanks, Kristoffer! I will look at this shortly.

Hi Kristofer,

Are you using the Enonic STK? It has a weakness with anchors. It should stop when a character after “page://” is not numeric. But it doesn’t.

So the error is in that case not in Enonic CMS but in the STK files doing the html parsing.


Yep, we’re using the STK plugin to render the HTML:

<xsl:call-template name="stk:html.process">
    <xsl:with-param name="document" select="contentdata/textarea" />

If the code is open sourced, I’m sure I could submit a pull request.

Thank you for your quick reply!

Hi again,

Yes it is open source.

The issue is here:

And the repo is here:

Great then :slight_smile:

Here’s your pull request