Current Page URL Shortcode in Content

Inside a page, I want to output the current, full, absolute url.

I created a shortcode:

  • Site
    ** layouts
    *** shortcodes
    **** page-url.html

    {{ $.Page.Params.Permalink | absURL }}

And I call this in:

  • Site
    ** content
    *** page.html

    {{< page-url >}}

However the output is not as expected, its just outputting the baseURL.

Is there some way to achieve this? What am I missing here?

Thanks in advance.

1 Like

Going to reply to my own thread here.

I can do this by using the built in Hugo shortcode ref

In page.html

{{< ref "content/page.html" >}}

Feels weird to have to manually type the file path. I might be able to refactor this so its a variable.

It look at what you ask : .Params in your page.

Try {{ $.Page.Permalink }} and {{ .Page.Permalink }}

And no need to absURL. .Permalink is already absolute

1 Like