Thank you for the help. I understand the principle of template lookup order, but what I don’t understand how to do template inheritance gracefully.
The relearn theme’s single.html
template (themes/relearn/layouts/_default/single.html) just says this:
{{- partial "_main.hugo" . }}
…which I gather is a reference to this partial: themes/relearn/layouts/partials/_main.hugo… which contains:
{{- partialCached "page-meta.hugo" . .RelPermalink }}
{{- $outputFormat := partial "output-format.hugo" . }}
{{- partial "output-partial.hugo" (dict "base" "header" "page" . "parameter" . "outputFormat" $outputFormat) }}
{{- if not .File }}
{{- partial "output-partial.hugo" (dict "base" "body" "page" . "parameter" (dict "page" . "content" (partial "output-partial.hugo" (dict "base" "initial" "page" . "parameter" . "outputFormat" $outputFormat))) "outputFormat" $outputFormat) }}
{{- else }}
{{- partial "output-partial.hugo" (dict "base" "body" "page" . "parameter" (dict "page" . "content" (partial "output-partial.hugo" (dict "base" "content" "page" . "parameter" . "outputFormat" $outputFormat))) "outputFormat" $outputFormat) }}
{{- end }}
{{- partial "output-partial.hugo" (dict "base" "footer" "page" . "parameter" . "outputFormat" $outputFormat) }}
…and then themes/relearn/layouts/partials/output-partial.hugo
has this:
{{- $base := .base }}
{{- $page := .page }}
{{- $parameter := .parameter }}
{{- $outputFormat := .outputFormat }}
{{- if not $outputFormat }}
{{- $outputFormat = partial "output-format.hugo" $page }}
{{- end }}
{{- $suffix := partialCached "output-suffix.hugo" $page $page.RelPermalink $outputFormat }}
{{- $f := printf "/layouts/partials/%s.%s.%s" $base $outputFormat $suffix }}
{{- if or (not $outputFormat) (not (partialCached "fileExists.hugo" $f $f)) }}
{{- $f = printf "/layouts/partials/%s.%s" $base $suffix }}
{{- if partialCached "fileExists.hugo" $f $f }}
{{- partial (printf "%s.%s" $base $suffix) $parameter }}
{{- end }}
{{- else }}
{{- partial (printf "%s.%s.%s" $base $outputFormat $suffix) $parameter }}
{{- end }}
…but at this point, I already feel like I’ve take a wrong turn!
I’m coming at this from years of working with jinja2/django/flask style templating, and I was thinking I could “extend” the relearn “single.html” template and then override blocks to write custom content. But when I look at the above relearn template files, I don’t see any obvious ways to override single.html
: How can I gracefully use this template, but, like, write my own {{ define "main" }}...{{ end }}}
block?
I know this must be a noob question for those familiar with writing hugo templates, but I bet a lot of hugo users, like me, have never needed to dig too deeply into this. A worked example, with a theme, would be really helpful.
Thank again for your help!