Get absURL for .Anchor (with "#") in render-heading.html

in render-heading.html based on render hooks templates we got this bit:

href="#{{ .Anchor | safeURL }}

which returns the anchor with hash on front.

Looking for a simple way (for other purpose inside render-heading.html to return an absolute url with anchor. For example https://example.com/post1/#anchor1.

Played with absURL, printf and path.Join without success.

This may be simple, but cannot get this sorted in simple manners. Any help?

Because this an href attribute, for an hyperlink.
You also need

id=" {{ .Anchor | safeURL }}

It got ID, like in link to render hooks templates.

My question is about getting full link absURL for anchor.

this works:
<a href="{{ print .Page.Permalink "#" .Anchor }}">{{ .Text }}</a>
But beware, I have unsafe = true.
I agree it doesn’t make a lot of sense. The site says

{{ absURL “style.css” }} → https://example.org/style.css`

so {{ absURL (print "#" .Anchor) }} should work too, but it doesn’t.

1 Like

Render Hooks hold the the page at .Page don’t they?

Won’t href="{{ $.Page.Permalink }}#{{ .Anchor | safeURL }}" work?

1 Like

Thanks @regis almost done.

{{ $.Page.Permalink }}#{{ .Anchor | safeURL }} > generate > "https://example.com/post1/""#""/anchor1"

But each thing returned inside its own brackets. There is progress. Will look tomorrow into joining them together. Thanks.

Thanks Tom, this is what I need :slight_smile:

1 Like

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