Is it possible to index $paginator.Pagers?

Hello! I am trying to make some advanced pagination links and am having trouble getting a link for a specific page using the index command. It’s weird though, because it doesn’t just outright fail, it just seems that I am unable to get any information about pages past the second.

This works:

{{ (index $paginator.Pagers 1).URL }}

This crashes hugo:

{{ (index $paginator.Pagers 2).URL }}

Any advice? Maybe I just can’t use index with pagers at all and I will have to write some really lame loops…

What does {{ len $paginator.Pagers }} gives you? Maybe index 2 doesn’t exist.

{{ len $paginator.Pagers }} returns 12 for the list I am testing with.

Then you code is valid. And shouldn’t cause any errors.

What does Hugo spits out in your terminal when it crashes?

But, without taking a look at the whole thing, it’s tough to say anything.

Here is the stack trace:

Building sites … ERROR 2018/08/03 11:16:43 Failed to render "_default/list.html": reflect: Zero(nil)
ERROR 2018/08/03 11:16:43 Stack Trace:
goroutine 71 [running]:
github.com/gohugoio/hugo/hugolib.stackTrace(0x4b0, 0xf14a71, 0x17)
        /go/src/github.com/gohugoio/hugo/hugolib/page.go:280 +0x7d
github.com/gohugoio/hugo/hugolib.(*Site).renderForLayouts.func1(0xc044a578a0, 0xc042014600)
        /go/src/github.com/gohugoio/hugo/hugolib/site.go:1742 +0x13c
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
text/template.errRecover(0xc044a57790)
        /usr/local/go/src/text/template/exec.go:143 +0x1c1
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
text/template.errRecover(0xc044a56af8)
        /usr/local/go/src/text/template/exec.go:143 +0x1c1
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
reflect.Zero(0x0, 0x0, 0x0, 0x0, 0x0)
        /usr/local/go/src/reflect/value.go:2171 +0x10e
text/template.(*state).validateType(0xc044a56a78, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc044a56498)
        /usr/local/go/src/text/template/exec.go:696 +0x6b9
text/template.(*state).evalArg(0xc044a56a78, 0xec3140, 0xc042d53400, 0x16, 0x0, 0x0, 0x10a3bc0, 0xc0420ac190, 0x18, 0xc042727348, ...)
        /usr/local/go/src/text/template/exec.go:745 +0x758
text/template.(*state).evalChainNode(0xc044a56a78, 0xec3140, 0xc042
ERROR 2018/08/03 11:16:43 Stack Trace:
goroutine 70 [running]:
github.com/gohugoio/hugo/hugolib.stackTrace(0x4b0, 0xf14a71, 0x17)
        /go/src/github.com/gohugoio/hugo/hugolib/page.go:280 +0x7d
github.com/gohugoio/hugo/hugolib.(*Site).renderForLayouts.func1(0xc0444a98a0, 0xc042014600)
        /go/src/github.com/gohugoio/hugo/hugolib/site.go:1742 +0x13c
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
text/template.errRecover(0xc0444a9790)
        /usr/local/go/src/text/template/exec.go:143 +0x1c1
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
text/template.errRecover(0xc0444a8af8)
        /usr/local/go/src/text/template/exec.go:143 +0x1c1
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
reflect.Zero(0x0, 0x0, 0x0, 0x0, 0x0)
        /usr/local/go/src/reflect/value.go:2171 +0x10e
text/template.(*state).validateType(0xc0444a8a78, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0444a8498)
        /usr/local/go/src/text/template/exec.go:696 +0x6b9
text/template.(*state).evalArg(0xc0444a8a78, 0xec3140, 0xc042d53680, 0x16, 0x0, 0x0, 0x10a3bc0, 0xc0420ac190, 0x10, 0xc04251f6a8, ...)
        /usr/local/go/src/text/template/exec.go:745 +0x758
text/template.(*state).evalChainNode(0xc0444a8a78, 0xec3140, 0xc042
ERROR 2018/08/03 11:16:43 Stack Trace:
goroutine 71 [running]:
github.com/gohugoio/hugo/hugolib.stackTrace(0x4b0, 0xf14a71, 0x17)
        /go/src/github.com/gohugoio/hugo/hugolib/page.go:280 +0x7d
github.com/gohugoio/hugo/hugolib.(*Site).renderForLayouts.func1(0xc044a57428, 0xc042014600)
        /go/src/github.com/gohugoio/hugo/hugolib/site.go:1742 +0x13c
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
text/template.errRecover(0xc044a57318)
        /usr/local/go/src/text/template/exec.go:143 +0x1c1
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
text/template.errRecover(0xc044a56680)
        /usr/local/go/src/text/template/exec.go:143 +0x1c1
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
reflect.Zero(0x0, 0x0, 0x0, 0x0, 0x0)
        /usr/local/go/src/reflect/value.go:2171 +0x10e
text/template.(*state).validateType(0xc044a56600, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc044a56020)
        /usr/local/go/src/text/template/exec.go:696 +0x6b9
text/template.(*state).evalArg(0xc044a56600, 0xec3140, 0xc042d58a00, 0x16, 0x0, 0x0, 0x10a3bc0, 0xc0420ac190, 0x18, 0xc042878fc8, ...)
        /usr/local/go/src/text/template/exec.go:745 +0x758
text/template.(*state).evalChainNode(0xc044a56600, 0xec3140, 0xc042
ERROR 2018/08/03 11:16:43 Stack Trace:
goroutine 70 [running]:
github.com/gohugoio/hugo/hugolib.stackTrace(0x4b0, 0xf14a71, 0x17)
        /go/src/github.com/gohugoio/hugo/hugolib/page.go:280 +0x7d
github.com/gohugoio/hugo/hugolib.(*Site).renderForLayouts.func1(0xc0444a9428, 0xc042014600)
        /go/src/github.com/gohugoio/hugo/hugolib/site.go:1742 +0x13c
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
text/template.errRecover(0xc0444a9318)
        /usr/local/go/src/text/template/exec.go:143 +0x1c1
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
text/template.errRecover(0xc0444a8680)
        /usr/local/go/src/text/template/exec.go:143 +0x1c1
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
reflect.Zero(0x0, 0x0, 0x0, 0x0, 0x0)
        /usr/local/go/src/reflect/value.go:2171 +0x10e
text/template.(*state).validateType(0xc0444a8600, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0444a8020)
        /usr/local/go/src/text/template/exec.go:696 +0x6b9
text/template.(*state).evalArg(0xc0444a8600, 0xec3140, 0xc042158000, 0x16, 0x0, 0x0, 0x10a3bc0, 0xc0420ac190, 0x10, 0xc04290f588, ...)
        /usr/local/go/src/text/template/exec.go:745 +0x758
text/template.(*state).evalChainNode(0xc0444a8600, 0xec3140, 0xc042
ERROR 2018/08/03 11:16:43 Stack Trace:
goroutine 72 [running]:
github.com/gohugoio/hugo/hugolib.stackTrace(0x4b0, 0xf14a71, 0x17)
        /go/src/github.com/gohugoio/hugo/hugolib/page.go:280 +0x7d
github.com/gohugoio/hugo/hugolib.(*Site).renderForLayouts.func1(0xc04323b8a0, 0xc042014600)
        /go/src/github.com/gohugoio/hugo/hugolib/site.go:1742 +0x13c
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
text/template.errRecover(0xc04323b790)
        /usr/local/go/src/text/template/exec.go:143 +0x1c1
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
text/template.errRecover(0xc04323aaf8)
        /usr/local/go/src/text/template/exec.go:143 +0x1c1
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
reflect.Zero(0x0, 0x0, 0x0, 0x0, 0x0)
        /usr/local/go/src/reflect/value.go:2171 +0x10e
text/template.(*state).validateType(0xc04323aa78, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc04323a498)
        /usr/local/go/src/text/template/exec.go:696 +0x6b9
text/template.(*state).evalArg(0xc04323aa78, 0xec3140, 0xc042d54500, 0x16, 0x0, 0x0, 0x10a3bc0, 0xc0420ac190, 0x11, 0xc042745488, ...)
        /usr/local/go/src/text/template/exec.go:745 +0x758
text/template.(*state).evalChainNode(0xc04323aa78, 0xec3140, 0xc042
ERROR 2018/08/03 11:16:43 Stack Trace:
goroutine 72 [running]:
github.com/gohugoio/hugo/hugolib.stackTrace(0x4b0, 0xf14a71, 0x17)
        /go/src/github.com/gohugoio/hugo/hugolib/page.go:280 +0x7d
github.com/gohugoio/hugo/hugolib.(*Site).renderForLayouts.func1(0xc04323b428, 0xc042014600)
        /go/src/github.com/gohugoio/hugo/hugolib/site.go:1742 +0x13c
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
text/template.errRecover(0xc04323b318)
        /usr/local/go/src/text/template/exec.go:143 +0x1c1
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
text/template.errRecover(0xc04323a680)
        /usr/local/go/src/text/template/exec.go:143 +0x1c1
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
reflect.Zero(0x0, 0x0, 0x0, 0x0, 0x0)
        /usr/local/go/src/reflect/value.go:2171 +0x10e
text/template.(*state).validateType(0xc04323a600, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc04323a020)
        /usr/local/go/src/text/template/exec.go:696 +0x6b9
text/template.(*state).evalArg(0xc04323a600, 0xec3140, 0xc042d58c80, 0x16, 0x0, 0x0, 0x10a3bc0, 0xc0420ac190, 0x11, 0xc042d77928, ...)
        /usr/local/go/src/text/template/exec.go:745 +0x758
text/template.(*state).evalChainNode(0xc04323a600, 0xec3140, 0xc042
ERROR 2018/08/03 11:16:43 Stack Trace:
goroutine 72 [running]:
github.com/gohugoio/hugo/hugolib.stackTrace(0x4b0, 0xf14a71, 0x17)
        /go/src/github.com/gohugoio/hugo/hugolib/page.go:280 +0x7d
github.com/gohugoio/hugo/hugolib.(*Site).renderForLayouts.func1(0xc04323b8a0, 0xc042014600)
        /go/src/github.com/gohugoio/hugo/hugolib/site.go:1742 +0x13c
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
text/template.errRecover(0xc04323b790)
        /usr/local/go/src/text/template/exec.go:143 +0x1c1
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
text/template.errRecover(0xc04323aaf8)
        /usr/local/go/src/text/template/exec.go:143 +0x1c1
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
reflect.Zero(0x0, 0x0, 0x0, 0x0, 0x0)
        /usr/local/go/src/reflect/value.go:2171 +0x10e
text/template.(*state).validateType(0xc04323aa78, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc04323a498)
        /usr/local/go/src/text/template/exec.go:696 +0x6b9
text/template.(*state).evalArg(0xc04323aa78, 0xec3140, 0xc042d58000, 0x16, 0x0, 0x0, 0x10a3bc0, 0xc0420ac190, 0x1c, 0xc0428a3c48, ...)
        /usr/local/go/src/text/template/exec.go:745 +0x758
text/template.(*state).evalChainNode(0xc04323aa78, 0xec3140, 0xc042
ERROR 2018/08/03 11:16:43 Stack Trace:
goroutine 72 [running]:
github.com/gohugoio/hugo/hugolib.stackTrace(0x4b0, 0xf14a71, 0x17)
        /go/src/github.com/gohugoio/hugo/hugolib/page.go:280 +0x7d
github.com/gohugoio/hugo/hugolib.(*Site).renderForLayouts.func1(0xc04323b428, 0xc042014600)
        /go/src/github.com/gohugoio/hugo/hugolib/site.go:1742 +0x13c
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
text/template.errRecover(0xc04323b318)
        /usr/local/go/src/text/template/exec.go:143 +0x1c1
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
text/template.errRecover(0xc04323a680)
        /usr/local/go/src/text/template/exec.go:143 +0x1c1
panic(0xd93f00, 0x10926b0)
        /usr/local/go/src/runtime/panic.go:502 +0x237
reflect.Zero(0x0, 0x0, 0x0, 0x0, 0x0)
        /usr/local/go/src/reflect/value.go:2171 +0x10e
text/template.(*state).validateType(0xc04323a600, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc04323a020)
        /usr/local/go/src/text/template/exec.go:696 +0x6b9
text/template.(*state).evalArg(0xc04323a600, 0xec3140, 0xc0423c4280, 0x16, 0x0, 0x0, 0x10a3bc0, 0xc0420ac190, 0x1c, 0xc044db56a8, ...)
        /usr/local/go/src/text/template/exec.go:745 +0x758
text/template.(*state).evalChainNode(0xc04323a600, 0xec3140, 0xc042
Total in 173 ms
Error: Error building site: logged 9 error(s)

I pushed up a bare-bones repository that crashes when you run hugo serve

https://github.com/zinefer/hugo-pagers-crash

Interestingly, I noticed while creating this example, that if I run a hugo serve and then save my partial, hugo reloads it and processes the output just fine.

You need to check for nil – not all paginators will have a page 2 etc.

{{ with index $paginator.Pagers 1 }}
{{ .URL }}
{{ end }}

That makes so much sense! thanks!