I have a function whose job is to return a file in the current language, but fall back to the default language if it can’t be found. An example of calling the partial is as follows:
{{ $bannerText := partial "functions/GetSection" (dict "sectionName" "announcement-banner" "Page" .Page) }}
And the function itself looks like this:
{{ $sectionName := .sectionName }}
{{ $section := (where (where .Page.Site.RegularPages "File.Dir" "in" (slice "_content-components\\" "_content-components/")) "File.TranslationBaseName" $sectionName) }}
{{ range .Page.Site.Home.Translations }}
{{ $section = $section | lang.Merge (where .Page.Site.RegularPages "File.TranslationBaseName" $sectionName) }}
{{ end }}
{{ return index $section 0 }}
Whenever I build my site, I get a warning:
WARN 2023/02/14 16:19:30 .File.TranslationBaseName on zero object. Wrap it in if or with: {{ with .File }}{{ .TranslationBaseName }}{{ end }}
The only place in my code using .File.TranslationBaseName
is the function above, but I’m not sure of how to refactor such that I can silence that warning.
Any recommendations?