Hi folks.
I’m trying to build a flexible sidebar, where a section can select what sidebar to use. The most common is a full depth tree of all pages in that section. The section can select which sidebar to use by specifying sidebar_type
in its front-matter. It doesn’t have to specify anything, however.
That’s the background. The issue I’m running into is in the template, however. Specifically, this:
{{ with .CurrentSection.Params.sidebar_type }}
Foo
{{end}}
Is generating the dreaded:
Building sites … ERROR 2018/08/07 14:47:14 Failed to render "/home/crell/Platformsh/hugotest/layouts/_default/list.html": runtime error: invalid memory address or nil pointer dereference
Using just {{ with .CurrentSection }}
runs. But as soon as I add .Params
it starts erroring out. (The error message is entirely unhelpful, of course. It took me over an hour of trial and error to even find what line it was actually complaining about.)
Per this previous thread: Runtime error: invalid memory address or nil pointer dereference
Isn’t the whole point of with
that it checks to make sure the values are non-nil and so it’s safe to use? Am I completely misunderstanding what with
does (entirely possible), and if so, what should I be doing here instead?
Does anyone know of an existing sample of what I’m trying to do, or a portion thereof, that I can shamelessly copy rather than reinventing it?