# Access paginator from header

**URL:** <https://discourse.gohugo.io/t/access-paginator-from-header/12131>\
**Category:** support\
**Tags:** pagination\
**Created:** [May 24, 2018, 9:40am UTC](https://discourse.gohugo.io/t/access-paginator-from-header/12131 "2018-05-24T09:40:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![iBasher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ibasher/32/6157_2.png) [@iBasher](https://discourse.gohugo.io/u/iBasher)\
**Post date:** [May 24, 2018, 9:40am UTC](https://discourse.gohugo.io/t/access-paginator-from-header/12131/1 "2018-05-24T09:40:29Z")

</div>

I`m trying to make rel links in \<head:  
\<lnk rel=“prev” href=“part1.html”  
\<lnk rel=“next” href=“part3.html”

but when i try to access .Paginator i get error

ERROR 2018/05/24 12:37:41 Error while rendering “home” in “”: template: C:\Hugo\[www.example.com](http://www.example.com)\themes\theme\layouts\_default\list.html:6:33: executing “main” at \<.Paginate\>: error calling Paginate: **a Paginator was previously built for this Node without filters; look for earlier .Paginator usage**

I`m new to Hugo, an would appreciate any help

---

<div class="post-metadata">

**Author:** ![Jura](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jura/32/13581_2.png) [@Jura](https://discourse.gohugo.io/u/Jura)\
**Post date:** [May 24, 2018, 10:28am UTC](https://discourse.gohugo.io/t/access-paginator-from-header/12131/2 "2018-05-24T10:28:19Z")

</div>

I think you can check with `.HasPrev` and `.HasNext` to see if a next or previous pagination page is available.

For your case, that would look like this I think:

```auto
{{ if .Paginator.HasPrev }}
    <link rel="prev" href="{{ .Paginator.Prev.URL }}">
{{ end }}

{{ if .Paginator.HasNext }}
    <link rel="next" href="{{ .Paginator.Next.URL }}">
{{ end }}

```

---

<div class="post-metadata">

**Author:** ![iBasher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ibasher/32/6157_2.png) [@iBasher](https://discourse.gohugo.io/u/iBasher)\
**Post date:** [May 24, 2018, 10:49am UTC](https://discourse.gohugo.io/t/access-paginator-from-header/12131/3 "2018-05-24T10:49:09Z")

</div>

> [@Jura](#):
>
> {{ if .Paginator.HasPrev }} \<link rel=“prev” href=“{{ .Paginator.Prev.URL }}”\> {{ end }} {{ if .Paginator.HasNext }} \<link rel=“next” href=“{{ .Paginator.Next.URL }}”\> {{ end }}

as i told befote _when i try to access .Paginator from header i get error_  
i think thats because i`m using custom pagination further in code, but i need it too )

---

<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 24, 2018, 10:52am UTC](https://discourse.gohugo.io/t/access-paginator-from-header/12131/4 "2018-05-24T10:52:58Z")

</div>

This is a little hard to explain in few words:

- But the paginator is static, so it is created the first time you access it (with .Paginate or .Paginator)
- You are accessing it in the header then changing it later, this does not work

I suggest you look into base templates and blocks and make sure it is created with the params you want before you access it.

---

<div class="post-metadata">

**Author:** ![iBasher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ibasher/32/6157_2.png) [@iBasher](https://discourse.gohugo.io/u/iBasher)\
**Post date:** [May 24, 2018, 10:58am UTC](https://discourse.gohugo.io/t/access-paginator-from-header/12131/5 "2018-05-24T10:58:51Z")

</div>

Well, it`s obvious. But i was hoping to see some simple examples how to handle it 🙂

---

<div class="post-metadata">

**Author:** ![iBasher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ibasher/32/6157_2.png) [@iBasher](https://discourse.gohugo.io/u/iBasher)\
**Post date:** [June 7, 2018, 8:07am UTC](https://discourse.gohugo.io/t/access-paginator-from-header/12131/6 "2018-06-07T08:07:55Z")

</div>

No thoughts? This links important for SEO, so I will be grateful for any help

---

<div class="post-metadata">

**Author:** ![Yudy\_Ananda](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/yudy_ananda/32/5664_2.png) [@Yudy\_Ananda](https://discourse.gohugo.io/u/Yudy_Ananda)\
**Post date:** [June 7, 2018, 11:29am UTC](https://discourse.gohugo.io/t/access-paginator-from-header/12131/7 "2018-06-07T11:29:48Z")

</div>

Here’s my workaround

This is part of the `<head>` for my index page

```
<!-- ROBOTS POSTS INDEX -->
{{ if $.Scratch.Get "blogs" }}
{{ $paginator := .Paginate (where .Data.Pages "Type" "article") 6 }}
	{{ if not $paginator.HasPrev }}
		<meta name="robots" content="index, follow">
	{{ else }}
		<meta name="robots" content="noindex, follow" />
	{{ end }}
	{{ if $paginator.HasPrev }}
		<link rel="prev" href="{{ .Paginator.Prev.URL }}" />

	{{ end }}
	{{ if $paginator.HasNext }}
		<link rel="next" href="{{ .Paginator.Next.URL }}" />
	{{ end }}
{{ end }}

```

this is part where the list.html or pagination part

```
<!-- I move this part into my head
{{ $paginator := .Paginate (where .Data.Pages "Type" "article") 6 }}
-->
{{ range $paginator.Pages }} 
 ....your index here

```

As you can see I move the part of paginator `{{ $paginator := .Paginate (where....` to the head

Hope this help

---

<div class="post-metadata">

**Author:** ![iBasher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ibasher/32/6157_2.png) [@iBasher](https://discourse.gohugo.io/u/iBasher)\
**Post date:** [June 8, 2018, 9:02am UTC](https://discourse.gohugo.io/t/access-paginator-from-header/12131/8 "2018-06-08T09:02:13Z")

</div>

That`s helped a lot, but there was few errors, which i already fixed.  
First one resolved by adding “$paginator := .Paginate …” func one more time in list.html  
Second one is about Paginator doesn’t work for Kind page

So the final code is:

head-meta.html

```
{{if eq .Kind "taxonomy"}}
    {{ $paginator := .Paginate (where .Data.Pages "Type" "skin") (index .Site.Params "paginate" | default 10) }}
    {{ if $paginator.HasPrev }}
        <link rel="prev" href="{{ .Paginator.Prev.URL }}" />
    {{ end }}
    {{ if $paginator.HasNext }}
        <link rel="next" href="{{ .Paginator.Next.URL }}" />
    {{ end }}
{{ end }}

```

list.html

```
{{ $paginator := .Paginate (where .Data.Pages "Type" "skin") (index .Site.Params "paginate" | default 10) }}
{{ range $paginator.Pages }}
    {{ .Render "content" }}
{{ end }}

```

Thanks a lot everyone
