.File.Dir on zero object. Wrap it in if or with: {{ with .File }}{{ .Dir }}{{ end }}
and I’ve tracked it down to the following code:
{{- define "title" -}}
{{- if .Pages -}}
{{ $sections := split (trim .File.Dir "/") "/" }}
{{ $title := index ($sections | last 1) 0 | humanize | title }}
{{- default $title .Title -}}
{{- else -}}
{{ $title := .File | humanize | title }}
{{- default $title .Title -}}
{{- end -}}
{{- end -}}
in shared.html in the hugo-book theme. I’ve tried wrapping the whole thing in the suggested if block but that doesn’t seem to work. Right now I’m clueless how to solve this.
There is a long story here about the dot (".") and scope etc. that I will not get into, but if you replace “with .File” with “if .File”, it should work.
Thanks, that did solve the issue but I now get another warning that, somewhat ironically I think, tells me not to use .Dir as that’s being deprecated. Specifically,
Page's .Dir is deprecated and will be removed in a future release. Use .File.Dir
Using .File.Dir within the if block again throws the zero object error.
What I don’t understand is this: Using .File.Dir throws a zero object error while .Dir is being deprecated. My ‘corrected’ if block statement above uses .Dir which means the original .File.Dir was correct, so why does the suggestion following the warning (see my OP) tell me to use deprecated code?
Since it’s just a warning right now I’ve been running things anyway, but I hope this can be solved somehow. At this point I’m even wondering if this is an issue with Hugo.
I take that back. I forgot that I did some template magic to handle these, and it looks like it is missing out in some of your if/else constructs … not sure, but I will have a look.
@bep@zwbetz Thank you both for this. I’ll follow on GitHub hoping for a solution and probably update this thread too if we find something, just for future reference.