Copied “as is” from the bug report that wasn’t considered a bug.
I believe I’ve found a problem with the usage of range
as described in Example #3 of Templating Introduction to access to the current offset in an iteration after updating to Hugo 0.48.
I’ll provide all information plus the testing repository for search engine indexing sake:
/content/some-file.md
---
title: "Some File"
url: /some-file
breadcrumbs:
- name: "Trail #1"
url: "/url-for-trail-1"
- name: "Trail #2"
url: "/url-for-trail-2"
- name: "Trail #3"
url: "/url-for-trail-3"
---
Duis ut minim consectetur ex eiusmod quis elit velit et veniam deserunt qui elit pariatur duis eu elit est mollit deserunt ad eu dolor nisi deserunt.
/themes//layouts/default/single.html
{{ if (.Params.breadcrumbs) "!=" nil }}
{{- $.Scratch.Set "breadcrumbs" slice -}}
{{- $.Scratch.Add "breadcrumbs" (slice (dict "url" ("/" | absLangURL) "name" "Home" "position" 1 )) -}}
{{ range $index, $element := (.Params.breadcrumbs) }}
{{- $.Scratch.Add "breadcrumbs" (slice (dict "url" .url "name" .name "position" (add $index 2))) -}}
{{ end }}
{{- $length := len ($.Scratch.Get "breadcrumbs") -}}
{{- range $index, $.Scratch.Get "breadcrumbs" -}}
{{ if eq ( (int .position) ) $length }}
<span class="breadcrumb-item active">{{ .name }}</span>
{{- else -}}
<a class="breadcrumb-item" href="{{ .url | absURL }}" >{{ .name }} > </a>
{{- end -}}
{{ end }}
{{ end }}
In Hugo 0.47 this compiles and the Breadcrumb Trail appears as expected:
Home > Trail #1 > Trail #2 > Trail #3
In Hugo 0.48 and 0.49, however, it yields an error saying $index
is not defined and shuts down the server:
Building sites . ERROR 2018/09/26 10:42:25 Error while rendering “page” in “”: template: page\single.html:27:44: executing “main” at <“breadcrumbs”>: undefined variable: $index
Total in 9 ms
Error: Error building site: logged 1 error(s)
I’ve searched about but I didn’t find anything mentioning that something changed. Did something really changed and the docs haven’t been updated?
As you see, I read the manual, I followed all the procedures (code, repository, log…) but it still not a bug and I’ve been kicked out Github to here.
So much for trying variable reassignments…