GetPage removes the anchor

I have the following snippet in a partial:

  {{ $mypage := ""}}
  {{ with $.GetPage $mypage }}
   {{ .RelPermalink }}
  {{ end }}

I get: /mypage/

while I would have been expecting: /mypage/#myanchor

Is there a way to keep the anchor with GetPage, or another similar function. Otherwise, I can split the string if detecting #, evaluate the link, then add back the anchor, but if there is a standard option I am missing, that migth be better.

Didn’t find such option on GetPage, you probably need to handle it yourself.

Btw what are your use cases of this? There are some useful functions/shortcodes like relref and ref for getting the URL of pages, which will keep the anchor/fragment.

relref and ref appear to only work in shortcodes, not partials. If you have an option to have them work in partials, let me know.

Use case: I have a partial at the bottom of my articles with the references. In the markdown file, I have a section references at the top. Sometimes the point to external URLs, sometimes to other articles section on the site.

The ref and relref functions can be used in partials/templates. And Hugo offers related shortcodes for users.

1 Like

Thanks. I had forgotten to pass the page context. Working now.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.