Hugo

Range over pages and page variables access

hello!
I am not sure I understand why it does not work ($page.Params.Tags is zero length, while it is not)

{{range $index, $page := .Data.Pages.ByPublishDate.Reverse}}
            {{range $page.Params.Tags}}
                {{$page.Title}} - {{.}} <br/>
            {{end}}
{{end}}

But if I just change $page.Params.Tags to .Params.Tags it works…

{{range $index, $page := .Data.Pages.ByPublishDate.Reverse}}
            {{range .Params.Tags}}
                {{$page.Title}} - {{.}} <br/>
            {{end}}
{{end}}

Why is so?

Because inside of a range the dot (.) is the currently ranged page or item. If you ask why $page.Params.xxx does not work… hmm… not sure ;] I would have used the dot though to begin with out of a diffuse feeling.

Strange, $page.Title is working fine for instance.

Well, the way I understand is that $page is the current page. Which could well be a list page. Maybe those variables were overwriting each other. try calling it $index, $pageitem instead?

Well, same result – empty list.

{{range $index, $page := .Data.Pages.ByPublishDate.Reverse}}
            {{ printf( "%v" $page) }}
            {{range $page.Params.Tags}}
                {{$page.Title}} - {{.}} <br/>
            {{end}}
{{end}}

Try debugging the $page variable. My guess is that $page.params is not an array/slice.

While at it, try .Pages in your first line. The docs say it’s preferred over .Data.Pages.

While reading further: there is {{ $.Param "header_image" }} that might work with $page.Param.