In 0.65.1, though, when this partial is included in a 404 template, I get: error calling IsAncestor: runtime error: invalid memory address or nil pointer dereference
Presumably this is due to how sections are handled? In any case, I’m having a tough time debugging it. I tried swapping over to this:
{{ if ne .Section nil }}
{{ $ancestor := .Section.IsAncestor .CurrentPage }}
...
{{ end }}
But that gives the same error, which I can’t quite follow – if .Section is nil, the assignment code shouldn’t be run, correct?
I may simply be messing up the template syntax, but it’s not obvious to me as to where. Any help would be appreciated.
Yap. I have the same problem. I think it is a combination having a custom 404.html and calling page variables. There is already an issue v0.65.0 breaks breadcrumb snippet
I’m sorry about this breakage, but it’s all for a greater good. I fixed the .Parent vs 404 and other such “standalone pages”, but I didn’t check the other related methods (.IsAncestors etc.) Sadly we did not have any tests covering it and none of the many sites I tested with caught this issue.
Thanks for your responsiveness, @bep! No worries; I know how hard it can be to find these edge cases before stuff is out in the wild. Glad it’s tracked down, and looking forward to checking out the new functionality in in 0.65.*!
I checked that when using .FirstSection.Permalink in version 0.65.2, Hugo get error and when using .CurrentSection.FirstSection.Permalink in all version except 0.65.2, Hugo get error.
So I had to check Hugo version like this
{{ if eq hugo.Version "0.65.2" }}{{ .CurrentSection.FirstSection.Permalink }}{{ else }}{{ .FirstSection.Permalink }}{{ end }}