I have this code I use inside a partial in Hugo to pass context to it.
{{- $ctx := . -}}
{{- $curPage := .page -}}
{{- $otherVar := .otherVar -}}
{{- with $curPage -}}
{{ $section := .CurrentSection }}
{{ if .IsHome }}
<span class="post-section"><a href="{{ $section.Permalink }}" target="_blank">{{ $section.Title }}</a></span>
{{ else }}
<a href="{{ $section.Permalink }}"> {{ $section.Title }}</a>
{{ end }}
{{- end -}}
I then add {{- $curPage := . -}}
at the top of the template where I want the partial to appear, then call the partial as {{ partial "partial-name.html" (dict "page" $curPage "otherVar" .) }}
. However, the content returns nil on the homepage while it works everywhere else sitewide. Could anyone look at my code and tell me where I went wrong?
Sorry - didn't see your with statement.
So {{- $curPage := .page -}}
is a typo.
.Page
Tested on local - most present version of hugo.
Also note - I don't think homepage has a section so your span will output very little as most of the currentsection or section related will return nothing.