Right now in my baseof.html I am calling a partial called head.html which contains the entireity of my <head> tag. That partial defines <title>{{ .Title | plainify }}</title> but I just came across the situation of wanting to customize the title for one single kind (“authors”).
I tried using blocks and putting a {{ define "head/title" . }} in the partial to make the page title overridable, or defining it in baseof.html and then calling it (which is ugly and also didn’t work).
It sounds like maybe using blocks isn’t right for this (but then they don’t seem that useful?).
I understand it could be done by putting all of my <head> code into baseof.html directly, and then just using define blocks, but I think having the head split out into a different file makes the base template much more readable.
I could also do this by just putting an if statement in the head partial, but that means I have code that’s purely for the authors kind mixed in with head, instead of everything related to authors being in layouts/authors/.
What is the most idiomatic way to make my <title> overridable in a single template?
By setting the title content as a block, and then you can define it in the template you want to override it in.
Last I knew it only worked on the baseof.html file (Unless hugo contributors figured out how to solve this). So you may have to either put it out of order a bit, or break up your head partials and put it between them.
The {{ .Title }} | {{ .Site.Title }} is used by default unless overridden by a certain template. The partial blocks bring in contents from layouts/_partials/head/meta.html and layouts/_partials/head/links.html, respectively. I usually override for my home template, such as:
home.html
{{ define "title" }}{{ .Site.Title }}{{ end }}
This is the best way I have found that allows me to break up the templates using partials, while still maintaining the ability to override the title tags.