Migrating templates to the new template system (v0.146.0 and later)

When Hugo v0.146.0 introduced the new template system, we added a one-page summary of the changes to the documentation while we worked on a full update. That update is done, and the documentation now describes how templates work today. Migration steps are less useful with each release, so we removed the summary. Nothing in this topic is new. It keeps the summary’s migration guidance for anyone who still needs to update a project or module.

The documentation describes the new system in detail:

Before you start

  • Commit your work, or back up your layouts directory.
  • Build your site and save a copy of the public directory. After migrating, build again and compare the output to make sure nothing changed unexpectedly.
  • If your project uses modules, including themes, update them to the latest versions first.

Rename directories

Old New
layouts/partials/ layouts/_partials/
layouts/shortcodes/ layouts/_shortcodes/
layouts/_default/_markup/ layouts/_markup/

You don’t need to change calls to the partial function. For example, {{ partial "header.html" . }} finds layouts/_partials/header.html.

Rename templates

Move the templates in layouts/_default/ up to the layouts/ directory, renaming them as shown below, then delete the _default directory. See the sections below for taxonomy templates and base templates.

Old New
layouts/index.html layouts/home.html
layouts/index.json layouts/home.json
layouts/index.rss.xml layouts/home.rss.xml
layouts/_default/single.html layouts/page.html
layouts/_default/list.html layouts/list.html
layouts/_default/foo.html layouts/foo.html

A directory in layouts whose name doesn’t begin with an underscore represents a content path. For example, layouts/posts/ applies to pages in content/posts/. Move templates out of the layouts/section/ directory, and include the page kind in the file name of each custom layout template:

Old New
layouts/section/section.html layouts/section.html
layouts/section/list.html layouts/section.html
layouts/section/posts.html layouts/posts/section.html
layouts/section/foo.html, with layout: foo in front matter layouts/section.foo.html

Rename the templates in section directories:

Old New
layouts/posts/single.html layouts/posts/page.html
layouts/posts/list.html layouts/posts/section.html

Rename taxonomy templates

In the old system, a template named taxonomy.html rendered both taxonomy pages, such as /tags/, and term pages, such as /tags/red/, unless a more specific template existed: terms.html for taxonomy pages, or term.html for term pages. In the new system, taxonomy.html renders only taxonomy pages, and term.html renders only term pages.

Rename terms.html to taxonomy.html. Keep term.html as it is. What to do with an old taxonomy.html depends on which other templates you have:

Old templates New templates
taxonomy.html Copy taxonomy.html to term.html, then adjust each as needed
taxonomy.html and term.html No changes
taxonomy.html and terms.html Rename taxonomy.html to term.html, then rename terms.html to taxonomy.html
taxonomy.html, term.html, and terms.html Delete taxonomy.html, then rename terms.html to taxonomy.html

These rules apply to the templates in layouts/_default/, to the templates in layouts/taxonomy/, and to taxonomy-specific templates in a directory named after the plural taxonomy name, such as layouts/tags/. Move the templates in layouts/taxonomy/ as shown below, then apply the rules above:

Old New
layouts/taxonomy/list.html layouts/taxonomy.html and layouts/term.html
layouts/taxonomy/taxonomy.html layouts/taxonomy.html
layouts/taxonomy/term.html layouts/term.html
layouts/taxonomy/terms.html layouts/terms.html
layouts/taxonomy/tag.html layouts/tags/term.html
layouts/taxonomy/tag.terms.html layouts/tags/taxonomy.html
layouts/taxonomy/foo.html, with layout: foo in front matter layouts/taxonomy.foo.html

Without a term.html, list.html, or all.html template, Hugo publishes no term pages.

Rename base templates

Move base templates from layouts/_default/ to layouts/. If a base template’s file name has an identifier before baseof, separated by a hyphen, move the identifier after baseof, separated by a dot.

Identifiers in a base template’s file name match the file name of the template being rendered, not the page. For example, baseof.section.html applies to section.html, but not to list.html, even when list.html renders a section page. In the old system, the identifier matched the page, so some base templates need more than one new name:

Old New
layouts/_default/baseof.html layouts/baseof.html
layouts/_default/section-baseof.html layouts/baseof.section.html
layouts/_default/list-baseof.html layouts/baseof.list.html if layouts/list.html renders your home, section, taxonomy, and term pages. Otherwise, create baseof.home.html, baseof.section.html, baseof.taxonomy.html, and baseof.term.html as needed.
layouts/_default/single-baseof.html layouts/baseof.page.html, plus baseof.foo.html for each custom layout template, such as foo.html, that renders regular pages
layouts/_default/posts-baseof.html layouts/posts/baseof.section.html
layouts/posts/baseof.html No changes
layouts/posts/single-baseof.html layouts/posts/baseof.page.html

Rename templates with dots in their names

A dot now separates identifiers in a template file name, such as page.en.html or home.rss.xml. A dot can’t separate words in a custom layout or partial name.

Old New
layouts/_default/foo.bar.html, with layout: foo.bar in front matter layouts/foo-bar.html, with layout: foo-bar in front matter
layouts/partials/foo.bar.html, with {{ partial "foo.bar.html" . }} layouts/_partials/foo-bar.html, with {{ partial "foo-bar.html" . }}

Replace calls to _internal templates

Old New
{{ template "_internal/disqus.html" . }} {{ partial "disqus.html" . }}
{{ template "_internal/google_analytics.html" . }} {{ partial "google_analytics.html" . }}
{{ template "_internal/opengraph.html" . }} {{ partial "opengraph.html" . }}
{{ template "_internal/pagination.html" . }} {{ partial "pagination.html" . }}
{{ template "_internal/schema.html" . }} {{ partial "schema.html" . }}
{{ template "_internal/twitter_cards.html" . }} {{ partial "twitter_cards.html" . }}

To override one of these embedded templates, create a partial template with the same name, such as layouts/_partials/opengraph.html.

Simplify (optional)

The new system can make some templates unnecessary:

  • A single layouts/all.html can render every page.
  • Directories in layouts can be nested to match nested sections, such as layouts/blog/2026/section.html.
  • _shortcodes and _markup directories can be placed at any level, such as layouts/docs/_markup/render-link.html to render links in the docs section only.

See the examples in the template lookup order documentation.

Troubleshooting

If a page renders with an unexpected template, print the name of the template while debugging:

{{ templates.Current.Name }}

If you get stuck, start a new topic in the support category and include a link to your project’s repository.

11 Likes