Same code two places, getting an error in one but not the other "nil pointer evaluating interface"

Hi All
I hope this isn’t too obvious, because I’m stumped!

I have two content folders, “photos” and “projects”, both have JSON formatted markdown files with essentially the exact same variables and formatting.

Example from projects:

"longTitle":"Springfield (2009)",
"shortDescription":"A collection of photos from my first visit back home after moving to Los Angeles in 2009.",

Example from photos:

"shortTitle":"W 4th St Courts",
"longTitle":"West 4th Street Courts, aka 'The Cage'",
"shortDescription":"Two days at the infamous West 4th Street Courts, sometimes lovingly called \"The Cage\".",
"images":[{"asset":{"tags":["W 4th St Courts"],"url":""}}

In my single.html template for both I have a range:

{{ range .Params.images }}
<img src={{ .asset.url }}>
{{ end }}

It works fine for projects and puts the image urls in the src field as expected. But for photos I’m getting the following error:

execute of template failed: template: photos/single.html:12:20: executing "main" at <.asset.url>: nil pointer evaluating interface {}.url

In an attempt to debug, I got the raw data returned by the range using {{ .asset }} and got essentially the same response in both layouts:

map[tags:[W 4th St Courts] url:]

map[tags:[Springfield] url:]

I cannot for the life of me figure out why photos is throwing the nil pointer error, but projects is not. Any thoughts?

Just double checked my markdown file and seeing there is one rogue entry {"asset":null} which is causing the error.

So maybe not totally stumped for the life of me after all. :slight_smile:
Now need to figure out why I’m getting a null asset on my content build.

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