How to Get Request's URL "As It Is" in Shortcode?

Is there a way to get the request URL “as it is” such that if the requested URL has a file with extension at the end, it will appear in some kind of page variable?

From the image above, .Page.Permalink only shows the link towards the input file. It trimmed my requested index.amp.html on its own.

The current behavior:

File structure: content/en-us/components/
Request: http://holloway-seraphim:8080/en-us/components/note/index.amp.html
Got: http://holloway-seraphim:8080/en-us/components/note/

No additional permalink configurations is done. The page is generated using multiple format feature, which is why index.amp.html is very important for parsing.


  1. The investigation above was done inside a short-code.

You most likely need to enable uglyurls in your project.


Tried. It works on page level but not inside shortcode. Here’s a shortcode .Page.Permalink dump inside an AMP Page with uglyurls as true.

Have a quick read of this section of the documentation:

If you can use ref/relref-links at that location this might help.

Otherwise you might have to check which output format the current page is and breakup and insert the format-slug yourself.

Ah, check out the last sample on this reference:

That’s what you want.

{{ relref . (dict "path" "" "outputFormat" "amp") }}

I’m not trying to build URL link. The goal is to extract the request URL and perform some analysis functions on it (e.g. slice it up, parse, analyze for decision making).

Read my above reply =.="

Hugo is a static site generator. If you want to extract the request URL you need to use JavaScript.

Haha… Oops.

I meant by internal functions (for building the public/ artifact), not the front-end construction segment. I tested various ways to workaround the multiple outputs identification for shortcode. Seems like there is no way to work around it.

then again read my answers.

{{ $thelink := relref . (dict "path" "" "outputFormat" "amp") }}

This is the function that returns the URL of the current page in the output format you choose if you want to retrieve it in a layout.


  • You can redefine AMP to be permalinkable, see docs.
  • Or you can do (.OutputFormats.Get "amp").Permalink

The last one is probably not an option, since you don’t know the “current output format”.

Acutally you can identify easily using the OutputFormats - AlternativeOutputFormats math. I built a partial shortcode for it (checking against my data set for consistency):

{{- /* .               = Page data for processing                      */ -}}

{{- /* build dictionary checklist for checking all alternative formats */ -}}
{{- $list := dict -}}
{{- range $format := .Page.AlternativeOutputFormats -}}
        {{- $list = merge $list (dict $format.Name $format) -}}
{{- end -}}

{{- /* scan for current output format from the list of all formats     */ -}}
{{- $target := false -}}
{{- range $format := .Page.OutputFormats -}}
        {{- if not (index $list $format.Name) -}}
                {{- $target = $format -}}
        {{- end -}}
{{- end -}}

{{- /* process output                                                  */ -}}
{{- $ret := .Site.Data.bissetii.mediaTypes.HTML -}}
{{- if $target -}}
        {{- $ret = index .Site.Data.bissetii.mediaTypes $target.Name -}}
{{- end -}}
{{- $ret.Name -}}

The funny thing is when I inject this partial into both shortcode and the page itself, they both yield different results:

Do you mean “not knowing current format” by this phenomenon?

Please ignore:

  1. DEBUG PERMALINK – it was hardcoded to always find “amp”.
  2. DEBUG RELREF – the output. No matter how I play with it .Page.Permalink =.="

Also my main reason for parsing the request URL for the artifact construction. =.="

Tried the following:

{{- relref . (dict path  .Page.Permalink outputFormat "amp" -}}
{{- relref . (dict path .Page.Permalink outputFormat "AMP" -}}
{{- relref . (dict outputFormat "AMP" -}}

All do not have results.

As I said you cAnnot determine the current output format, and there are good reasons for that

Yeap. No workaround. It’s not possible to obtain requested URL for internal processing in shortcode.

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