Parse failed: undefined variable

Could anyone with more insight let me know why this code is failing? Removing the $attr part of the code makes the error disappear.

parse failed: template: _default/test.html:11: undefined variable "$heading"
{{ define "main" }}
{{- $heading := .Params.heading -}}
{{- $attr := "data-pagefind-body" -}}
{{- $attr := printf $attr | safeHTMLAttr }}
{{- end -}}
<h1 class="{{- if $heading }} {{- else }} {{- end }}">{{ .Title }}</h1>
{{- end -}}

The heading front matter value appears in the pages (.Kind "page") of a multipage post.

You end the block twice.

My bad! Just noticed that after posting this.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.