<index .Params.images 0>: error calling index: index of untyped nil

I created two ways of retrieving the first image in the following front matter of the author (index.md):

images:

  • “/authors/alfred/alfred.gif”
  • “/authors/alfred/study.jpg”

in layouts/_default/single.html I have the following:

{{- with .Params.author }}
{{- range where $.Site.RegularPages “Params.name” . }}

{{ index .Params.images 0 }} <- this gives the error

{{range $i,$v := .Params.images }}
{{ if not i }} {{ .Scratch.Set “photo” v }} {{end}} {{end}} {{.Scratch.Get “photo” }} <- this gives the image for me to use
{{- end }}{{ end }}

why does the index function generate an error?

The above fails when there are a page without the images params set. You can do this to avoid it:

{{ with .Params.images }}
{{ index . 0 }}
{{ end }}

2 Likes