# Access page data in a pager?

**URL:** <https://discourse.gohugo.io/t/access-page-data-in-a-pager/32842>\
**Category:** support\
**Tags:** pagination\
**Created:** [May 12, 2021, 3:19pm UTC](https://discourse.gohugo.io/t/access-page-data-in-a-pager/32842 "2021-05-12T15:19:05Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrillek](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/chrillek/32/19797_2.png) [@chrillek](https://discourse.gohugo.io/u/chrillek)\
**Post date:** [May 12, 2021, 3:19pm UTC](https://discourse.gohugo.io/t/access-page-data-in-a-pager/32842/1 "2021-05-12T15:19:05Z")

</div>

I’m using a custom pagination template basically like so

```auto
{{ $pag := $.Paginator }}
{{ range $pag.Pagers }}
...
 <a class="pagination-link {{ if eq . $pag }}is-current{{ end }}" 
        href="{{ .URL }}">{{ .PageNumber }}</a>
...
{{end}}

```

and it does what I want.

However, I’d like to include some information in the title of the `a` elements, something that can be retrieved from the front matter of the pages in this pager.  
If I understand the documentation correctly inside the `range`, `.Pages` should give me a (what - slice? map? something else?) of the pages in the current pager. According to `warnf #%v` I do get something that’s a list/slice/something of `Pages.page` objects, and I can get for example the first element of it with `first 1 .Pages`. However, this does not seem to be a `page`, since trying to access its front matter variables with `.Params.Variable` throws an error:  
`can't evaluate field Params in type page.Pages`  
Is there a way to get at the pages (or their URLs or anything that gets me a handle to them) in a pager?

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [May 13, 2021, 1:01pm UTC](https://discourse.gohugo.io/t/access-page-data-in-a-pager/32842/2 "2021-05-13T13:01:28Z")

</div>

Hmm, I saw this post and wondered if somebody would chime in to politely explain that it’s not possible. But nobody answered yet, so I try to add my two cents. Not possible 🙂

There is no way to access page data inside of a pager without additional work and it makes no sense to add this by default with internal tools, because it’s a pager, not a pag(e-rang)er. It’s function is navigation, not content.

But: You could in your `range` use the `getPage` function, to get the page in question and from there add the parts.

The problem here is, that this will probably lead to _very long_ build times. If you 100% need it, then live with a coffee break every now and then and use `getPage` inside of the range.

> **[.GetPage](https://gohugo.io/functions/getpage/#readout)**
>
> Gets a \`Page\` of a given \`path\`.

Another possible solution might be something along the line of not using pagination but ranging through your pages again and create your own “pager” by using something like `range (where .Pages "Type" "posts")`, but that too will increate the build time massively.

If you want to see whats inside your variable you could use a tool like debugprint by @kaushalmodi that iterates through your dot to see what is included.

> **[kaushalmodi/hugo-debugprint](https://github.com/kaushalmodi/hugo-debugprint)**
>
> Hugo "debugprint.html" partial. Contribute to kaushalmodi/hugo-debugprint development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![chrillek](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/chrillek/32/19797_2.png) [@chrillek](https://discourse.gohugo.io/u/chrillek)\
**Post date:** [May 13, 2021, 1:24pm UTC](https://discourse.gohugo.io/t/access-page-data-in-a-pager/32842/3 "2021-05-13T13:24:58Z")

</div>

Thanks for chiming in. I already suspected that it’s not possible. So I’ll give `.GetPage` a try – there are not so many pages anyway, so I could live with a coffee break now and then.  
Though I’m not clear on how to get the to _path_ for `.GetPage` from inside the pager. The `.URL` field is, as far as i can see, something like “…/page/3”, whereas I’d need “…/blog/post.html” or so.

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [May 13, 2021, 1:31pm UTC](https://discourse.gohugo.io/t/access-page-data-in-a-pager/32842/4 "2021-05-13T13:31:24Z")

</div>

Yeah, that’s why I added the debugprint note. I think you need to start with “debugging the dot” inside of a pagination range and see what you get. I am not sure what is included, because all I need is a label and a n URL up to this post 🙂

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [May 13, 2021, 1:44pm UTC](https://discourse.gohugo.io/t/access-page-data-in-a-pager/32842/5 "2021-05-13T13:44:34Z")

</div>

> [@chrillek](#):
>
> can’t evaluate field Params in type page.Pages

So,

- `.Paginator` and `.Paginate` returns a list of “paginator pages”
- Each paginator page has some methods, including `HasNext` and … `Pages`.

WIth that, it does not make sense to call `.Params` on a “paginator page”, because it does not have params…

So:

```auto
{{ range .Pages }}
// This is a paginator page, e.g. a group of pages
{{ range .Pages }}
// This is the page
Param: {{ .Param.foo }}
{{ end }}
{{ end }}

```

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [May 13, 2021, 1:46pm UTC](https://discourse.gohugo.io/t/access-page-data-in-a-pager/32842/6 "2021-05-13T13:46:17Z")

</div>

I should have known it’s already thought of.

---

<div class="post-metadata">

**Author:** ![chrillek](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/chrillek/32/19797_2.png) [@chrillek](https://discourse.gohugo.io/u/chrillek)\
**Post date:** [May 13, 2021, 2:18pm UTC](https://discourse.gohugo.io/t/access-page-data-in-a-pager/32842/7 "2021-05-13T14:18:31Z")

</div>

The inner `range .Pages` does not seem to contain anything. Neither does `warnf %#v .` print anything nor do I get any output from `Param: {{.Param.Title}}`. The context in the partial is this:

```auto
{{ $pag := $.Paginator }}
{{ range $pag.Pagers }}
    {{ range .Pages}}
    {{ range .Pages}}
    {{ warnf "%#v" .pageCommon}} <!-- no output -->
    Param {{ .Param.Title}} <!-- not output either -->
    {{end }}
    {{ end }}
... 
{{end}}

```

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [May 13, 2021, 2:20pm UTC](https://discourse.gohugo.io/t/access-page-data-in-a-pager/32842/8 "2021-05-13T14:20:01Z")

</div>

You are ranging `pages` twice. Why? You are aware of what the dot `.` means inside of a range?

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [May 13, 2021, 2:39pm UTC](https://discourse.gohugo.io/t/access-page-data-in-a-pager/32842/9 "2021-05-13T14:39:38Z")

</div>

> [@chrillek](#):
>
> ` {{ warnf "%#v" .pageCommon}} <!-- no output -->`

I would epxect that to … fail the build.

---

<div class="post-metadata">

**Author:** ![chrillek](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/chrillek/32/19797_2.png) [@chrillek](https://discourse.gohugo.io/u/chrillek)\
**Post date:** [May 13, 2021, 2:56pm UTC](https://discourse.gohugo.io/t/access-page-data-in-a-pager/32842/10 "2021-05-13T14:56:56Z")

</div>

I was merely repeating what @bep suggested [here](https://discourse.gohugo.io/t/access-page-data-in-a-pager/32842/5). I was wondering about the duplication of ranges, but supposed it was intended since there are also to `end` statements.  
Yes, I’m aware of "what the dot means.  
Investigating further, I get this to work a bit:

```auto
{{ range .Pages }}
    Param {{ .Param "country" }} <!-- works ok -->
    {{ end }}
    {{ $pag1 := first 1 .Pages}}
    {{ warnf "%s" ($pag1.Param "country") }} <!-- error -->

```

The `Param ...` part does what it’s supposed to do. However, attempting to get at the _first_ of the `.Pages` and then access the `.Param` gives an error:

```auto
 at <$pag1.Param>: can't evaluate field Param in type page.Pages

```

Same thing when using `with (first 1 .Pages)` and `.Param ...`.  
But `range first 1 .Pages ` is just fine…
