Isolated my problem - index not working correctly?

I created the GiHut repo:

To see the bug

  • Install Docker
  • Clone this repo.
  • Run the command “./runCompiler”

Or just use Hugo from a native install.

This will cause an error to be displayed. I have documented a line which, when removed, will not through an error.

Is this a bug or am I doing something wrong?


I realized I should describe the bug in this thread.

The problem is that (index $collection $variable) does not work reliably. The “hard coded” (index $collection “key-value”) does work.

I have trimmed down website in this repo that shows this problem very clearly. I can show the following:

{{ $key }}
{{ $value := (index $key) }}
{{ $key }}

What I get as a message is that the $key variable is nil. When I remove that line I see {{ $key }} display the expected value twice (expected).

This is now a serious blocker for my three web sites.

Any thoughts, tips, comments, etc. would be appreciated.


It would have been helpful if you’d mentioned that the code in question is in themes/theme/layouts/person/list.html. Since the repo doesn’t trigger an error as-is, I had to grep through to find it.

The fundamental problem is that your paginator doesn’t make sense.

{{ $paginator := .Paginate (where .Site.Pages "Type" "person") }}

should simply be:

{{ $paginator := .Paginate .Data.Pages }}

Why? Because you’re already in section person, so you don’t need to select all pages of type “person”; Hugo did that for you automatically. Your expression includes the section index page as well as the two single pages, and it didn’t have a valid value for, so the index lookup correctly failed. (also, should be

By the way, why is there a lightning bolt in the HTML tag? <html ⚡="">


1 Like

I feel a non-sequitur koan coming on…

Because this was an AMP page. “Accelerated Mobile Page” and that specification requires that tag. (I removed the other required elements for this GitHub repo to focus on the Hugo issue)

See: for details.

Sorry about the lack of clarity in my example!

Thank you very much for the tips and the explanation of the context for the range scan of person section pages. I find that understanding the context is one of the biggest challenges when learning Hugo. It never occurred to me that when working on a content section that the context would be that section. I am going to ponder this a bit today and see if I can get full clarity about this.

Thank you also for the great explanation of picking up the page. That makes total sense now.

The lighting bolt is to signal that a page is coded to the AMP specification. I removed all AMP required elements for this repo but I forgot that one!

I’ll rework my code this afternoon.

Again - thank you.