I had code that was doing this and hugo outright crashed without any error info. It would be nice if accessing fields of an invalid object would silently just return false. We have isset if we want to detect if it’s actually there. The workaround is somewhat awkward.
{{ $data := .Site.Data.something }}
{{ $table := $data.table }}
{{ if $table.field }}
...do something...
{{ end }}
Workaround, assuming $data is something required and is valid:
{{ $data := .Site.Data.something }}
{{ $table := or $data.table $data }}
{{ if $table.field }}
...do something...
{{ end }}
This may cause issues if field exists within $data, but I could use a dummy file as an empty map, unless there is a better way?
(side note: is there an assert function, or a way to print output a message or warning)
I do use with for simple things because it always fails for me when doing more advanced queries.
I’ll do some testing whenever I see an opportunity to try this out. Though, I tried putting the with within a pipeline just didn’t work.
Perhaps my errors were related to using index on a null data object, I’m not too sure. When I had the error it was after I changed a bunch of code. I haven’t had much luck with indexing into an object after I’ve upgraded to 0.13.