Files
hugoDocs/content/templates/lookup-order.md
T

2.5 KiB
Raw Blame History

title, linktitle, description, godocref, date, publishdate, lastmod, categories, tags, weight, draft, aliases, wip
title linktitle description godocref date publishdate lastmod categories tags weight draft aliases wip
Template Lookup Order Template Lookup Order The lookup order is a prioritized list used by Hugo as it traverses your files looking for the appropriate template to render your content. 2017-02-01 2017-02-01 2017-02-25
templates
lookup
fundamentals
15 false
true

Before creating your templates, it's important to know how Hugo looks for files within your project's directory structure.

Hugo uses a prioritized list called the lookup order as it traverses your files looking for the appropriate template to render your content.

The template lookup order is an inverted cascade: if template A isnt present or specified, Hugo will look to template B. If template B isn't present or specified, Hugo will look for template C...and so on until it reaches the layouts/_default/ directory for your project, or in the case of themes, themes/<THEME>/layouts/_default/. In many ways, the lookup order is similar to the control mechanism of a switch statement (i.e. without fallthrough) seen in many programming languages.

The power of the lookup order is that it enables you to craft specific layouts as needed without creating more templating than necessary, thereby keeping your templating DRY.

{{% note %}} Most Hugo websites will only need the default template files at the end of the lookup order (i.e. _default/*.html). {{% /note %}}

See examples of the lookup order for each of the Hugo template types: