Best way to dynamically output selected Page Variable (Not Custom Page Params)

I’m trying to loop on a map of keys and display the corresponding Page Variable. For this, I need to use a template variable ($whatever) to grab the Page Variable value. I know I cannot use index for that, but .Param or .Params are not helping either…)

This is an overly simplified illustrative example:

{{ $title := "Title" }}
{{ $permalink := "Permalink" }}

{{ .Param $title }} > works
{{ .Param $permalink }} > does not work

{{ index .Params $title }} > works
{{ index .Params $permalink }} > does not work

Only Title works.

Of course both methods work with Custom Page Params.

  1. Is .Param supposed to work with Page Variable (Doc says: Calls page or site variables into your template)
  2. Is there a way to achieve this?

Thanks a lot.

Of course .Permalink works… though directly in the Page context… can you tell the type of the dot context there?

If the context is the Page, directly doing .Permalink works… but that of course does not solve your intention to make that a variable.

As for .Param, unless I am mistaken, it only works for front-matter-set parameters and the parameters set in [Params] in your site’s config.toml/yaml/…

Further in the documentation, this line makes it a bit clearer:

You can use the .Param method to call these values into your template. The following will first look for an image param in a specific content’s front matter. If not found, Hugo will look for an image param in your site’s configuration:

@bep Would the “description” of that .Param help page like this be more accurate?

Calls variables set in page front-matter or site params into your template.

I am also looking for a better way… As Page is a struct, you cannot range through it, as it’s not a map.

So I resort to making my own map-like structure in the debugprint partial:

Thanks for your help @kaushalmodi.