Quantcast
Channel: .CurrentSection.Params generates nil pointer, even in with
Browsing latest articles
Browse All 7 View Live

.CurrentSection.Params generates nil pointer, even in with

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...

View Article



Image may be NSFW.
Clik here to view.

.CurrentSection.Params generates nil pointer, even in with

Try: {{ with .CurrentSection }} {{ .Params.sidebar_type }} {{end}} Crell: 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? Yes, but you need to...

View Article

.CurrentSection.Params generates nil pointer, even in with

Ah ha! OK, this is what I ended up with, and it doesn’t break on me: {{ with .CurrentSection }} {{ $sidebar_type := .Params.sidebar_type }} {{ if eq $sidebar_type "tree" }} {{ partial...

View Article

.CurrentSection.Params generates nil pointer, even in with

You could use {{ if .CurrentSection }} and get the same, I think, without the scope change. But I think it brings clarity to the code (it is shorter), and don’t find it annoying. Read full topic

View Article

.CurrentSection.Params generates nil pointer, even in with

In many cases I agree. However, with more complex logic I may want to access something from the original scope. I’ll try the if when that comes up next. Although… wouldn’t it be if...

View Article


Image may be NSFW.
Clik here to view.

.CurrentSection.Params generates nil pointer, even in with

Crell: .CurrentSection always exists That statement is not true, see hugolib package - github.com/gohugoio/hugo/hugolib - Go Packages .Params will always be non-nil. Read full topic

View Article

Image may be NSFW.
Clik here to view.

.CurrentSection.Params generates nil pointer, even in with

bep: I may want to access something from the original scope. Note that you can acess the original/outer-most scope by $ e.g. $.CurrentSection etc. Read full topic

View Article
Browsing latest articles
Browse All 7 View Live


Latest Images