How do I know the variables when ranging a site variable?

For example, when ranging .Pages how do I know that .Title is a variable of it. idk if i’m explaining myself.

When ranging a specific group of .Pages in a list template you can render the .Title variable of each page in that group provided that the title parameter is set in each content file.

If the title parameter is not present then no .Title will be rendered the list of pages.

To check for the existence of a variable have a look at the with function.

If you want to know what “keys” are available in any arbitrary structure you can use the following range to go through it and see what’s “in there”:

{{ range $key, $item := .Pages }}
<dt>{{ $key }}</dt>
<dd>{{ $item }}</dd>
{{ end }}

The output of {{ $item }} might vary depending on the content of the item.

Have a look at https://github.com/kaushalmodi/hugo-debugprint for a quick partial to debug anything in a nice table.

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