【发布时间】:2022-01-30 04:23:41
【问题描述】:
我在 Hugo 的部分代码中使用了这段代码来将上下文传递给它。
{{- $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 -}}
然后我将{{- $curPage := . -}} 添加到我希望部分显示的模板顶部,然后将部分调用为{{ partial "partial-name.html" (dict "page" $curPage "otherVar" .) }}。但是,该内容在主页上返回 nil,而它在站点范围内的其他任何地方都可以使用。谁能看看我的代码并告诉我哪里出错了?
【问题讨论】:
标签: go hugo hugo-content-organization