Reusable template code for page <head> tags (<title> and other)

Construction in baseof.html

<title>{{ .Title }} > My Site</title>

works for single pages. But when it comes to taxonomies list pages .Title is empty. I need taxonomies pages to have taxonomy metadata as <title>. Let’s take example

config.toml

[taxonomies]
    author = "authors"

_index.md in content/authors/jack-london

---
fullname: "Jack London"
---

Front matter of books by Jack London (yes, for some reasons I have to use already urlized names as tags)

authors:
- jack-london

First I need “Jack London” as <title> of /authors/jack-london page

{{ .Page.Params.fullname }} 

do the trick

Second I’d like code for <title> to be reusable for all pages. Logic something like

if page is single

{{ .Title }} else if page taxonomy {{ .Page.Params.fullname }}

Is it possible?

Have a look at how the documentation sets the base layout. The title is in a block and can be set by subsequent layout files.

This way you can add content to the title from further down the layouts by putting a {{ define "title" }} into your page layouts and then there locating the frontmatter variables you need in the title.

1 Like

Oops, just haven’t read that page and didn’t found it by search. Thank you and sorry for obvious question.

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