# Get page number

**URL:** <https://discourse.gohugo.io/t/get-page-number/41283>\
**Category:** support\
**Tags:** pagination\
**Created:** [November 4, 2022, 6:45am UTC](https://discourse.gohugo.io/t/get-page-number/41283 "2022-11-04T06:45:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhulse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mhulse/32/10531_2.png) [@mhulse](https://discourse.gohugo.io/u/mhulse)\
**Post date:** [November 4, 2022, 6:45am UTC](https://discourse.gohugo.io/t/get-page-number/41283/1 "2022-11-04T06:45:54Z")

</div>

I would like to be able to access the current pagination number in a partial.

Nothing seems to work.

I’ve even tried:

```auto
    {{ $paginatorString := (printf "%#v" .Paginator) }}
    {{ $paginatorString }}
    {{ if in $paginatorString "number:1" }}
      First page
    {{ end }}

    {{ $currentPageNumber := (index (split (index (split $paginatorString "number:") 1) ",") 0) }}
    ({{ $currentPageNumber }})

```

The above works (I had it in my navigation partial), but my page’s posts disappear.

I just need to see if I’m on the first page of pagination.

I suppose I could parse URL to see if “/posts/page/#/” exists.

Is there any good way to get `.PageNumber` outside of pagination?

Thanks!

---

<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:** [November 4, 2022, 10:32am UTC](https://discourse.gohugo.io/t/get-page-number/41283/2 "2022-11-04T10:32:26Z")

</div>

See [Pagination | Hugo](https://gohugo.io/templates/pagination/#build-the-navigation)

{{ .Paginator.PageNumber }} should give you what you want, I think.

---

<div class="post-metadata">

**Author:** ![mhulse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mhulse/32/10531_2.png) [@mhulse](https://discourse.gohugo.io/u/mhulse)\
**Post date:** [November 4, 2022, 4:22pm UTC](https://discourse.gohugo.io/t/get-page-number/41283/3 "2022-11-04T16:22:48Z")

</div>

> [@bep](#):
>
> {{ .Paginator.PageNumber }}

Thanks for the help!

I thought that would work too… Unfortunately, I get:

```auto
render of "page" failed: ".../layouts/_default/baseof.html:22:7": execute of template failed at <partial "partials/header/basic.html" .>: error calling partial: ".../layouts/partials/header/basic.html:5:17": execute of template failed at <.Paginator.PageNumber>: error calling PageNumber: runtime error: invalid memory address or nil pointer dereference render of "page" failed: invalid memory address or nil pointer dereference failed to render pages: invalid memory address or nil pointer dereference 

```

---

<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:** [November 4, 2022, 4:53pm UTC](https://discourse.gohugo.io/t/get-page-number/41283/4 "2022-11-04T16:53:45Z")

</div>

> [@mhulse](#):
>
> I thought that would work too… Unfortunately, I get:
> 
> ```auto
> 
> ```

Yea, and it’s impossible for me to help you debug that without the source. You should start by checking what you pass into the partial.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [November 4, 2022, 6:14pm UTC](https://discourse.gohugo.io/t/get-page-number/41283/5 "2022-11-04T18:14:34Z")

</div>

I suspect you are trying to the get the _pager_ number _before_ paginating the page collection.

This is a detailed description of the situation:  
[https://discourse.gohugo.io/t/determine-if-current-page-is-result-of-pagination/37494/4](https://discourse.gohugo.io/t/determine-if-current-page-is-result-of-pagination/37494/4)

The trick is to paginate _before_ trying to access the _pager_ number.  
[https://discourse.gohugo.io/t/control-pagination-and-page-collections-from-baseof-html/37643/8](https://discourse.gohugo.io/t/control-pagination-and-page-collections-from-baseof-html/37643/8)

---

<div class="post-metadata">

**Author:** ![mhulse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mhulse/32/10531_2.png) [@mhulse](https://discourse.gohugo.io/u/mhulse)\
**Post date:** [November 5, 2022, 2:26am UTC](https://discourse.gohugo.io/t/get-page-number/41283/6 "2022-11-05T02:26:24Z")

</div>

Thank you @jmooring! I can’t believe I missed this post when doing a search of the forum. 🤦‍♂️

Much appreciated!!!

---

<div class="post-metadata">

**Author:** ![mhulse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mhulse/32/10531_2.png) [@mhulse](https://discourse.gohugo.io/u/mhulse)\
**Post date:** [November 5, 2022, 2:29am UTC](https://discourse.gohugo.io/t/get-page-number/41283/7 "2022-11-05T02:29:05Z")

</div>

Thank you for the help @bep! Sorry for the lack of details. For the record, I was just passing the context into `basic.html` from `baseof.html`: `{{ partial "partials/header/basic.html" . }}`

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [November 7, 2022, 2:29am UTC](https://discourse.gohugo.io/t/get-page-number/41283/8 "2022-11-07T02:29:42Z")

</div>

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