ページを部品に分解する Partial と BlockTemplate について。

PartialTemplate

Partial templates
Partials are smaller, context-aware components in your list and page templates that can be used economically to keep your templating DRY.
Partial templates favicon https://gohugo.io/templates/partials/
Partial templates

layouts/_default/single.html

<html>
{{ partial "head.html" . }}
<body>
{{ partial "header.html" . }} {{ .Content }} {{ partial "footer.html" . }}
</body>
</html>

のように一部を部品で置き換える。

layouts/partials/head.html layouts/partials/header.html layouts/partials/footer.html

BlockTemplate

Base templates and blocks
The base and block constructs allow you to define the outer shell of your master templates (i.e., the chrome of the page).
Base templates and blocks favicon https://gohugo.io/templates/blocks/
Base templates and blocks

layouts/_default/single.html

{{ define "title" }}
{{ .Title }} &ndash; {{ .Site.Title }}
{{ end }}
{{ define "main" }}
{{ .Content }}
{{ end }}

のように自分が部品になる。 デフォルトでブロックテンプレート_default/baseof.html が選択される。

<html>
<head>
<title>{{ block "title" . }}
<!-- Blocks may include default content. -->
{{ .Site.Title }}
{{ end }}</title>
</head>
<body>
{{ block "main" . }}
<!-- The part of the page that begins to differ between templates -->
{{ end }}
</body>

Partial よりも BlockTemplate の方がきれいに分割できる気がするね。実際には両方使う。