Layout Lookup Order
On this page:
Looking at the extensive list of examples in the docs might be a bit overwhelming to new Hugo users, but it is not that complicated once we break it down.
Layout files are generally in the pattern:
1 2 3 4 5 6
layoutDir / [directory] / filename . [lang] . [outputformat] . suffix
Let’s look at each page .Kind to see how the values of these parts are affected:
Template Lookup by .Kind
home
content/_index.md => example.com/index.html
-
layoutDir: By default, the value islayouts. You can configure this value, but for the examples we will assume this default value is used. -
[directory]: its value can be (with highest priority on top)-
derived from
.Type- From the docs1
- So in the case of the homepage, the value will be either what is set on the frontmatter, or
"page".
-
-: For the homepage, the layout file can be located just belowlayouts/. -
"_default": default
-
-
filename: its value can be (with highest priority on top)- derived from
layoutset in the frontmatter. "index"- derived from the value of
.Kind:"home" "list": default
- derived from
-
[lang]- language code, eg
"en","fr", etc.
- language code, eg
-
[outputformat]- the output format name (eg
"amp") 2
- the output format name (eg
-
suffix- the output format suffix (eg
"html") 2
- the output format suffix (eg
Items #1, #4, #5, #6 are the same for .Kinds below.
section
content/posts/_index.md => example.com/posts/
-
[directory]: its value can be- derived from
.Type1 - derived from
.Kind:"section" "_default": default
- derived from
-
filename: its value can be- derived from
layoutset in the frontmatter. - derived from its
.Section, eg"posts". Not to be confused with 2.b or 3.c, which is the actual string"section", this is the value of the top-level directory undercontent. See docs for details. - derived from
.Kind:"section". Not to be confused with 3.b, this is the actual string"section". "list": default
- derived from
See above for #1, #4, #5, #6
page
content/posts/post-one.md => example.com/posts/post-one/
content/posts/post-one/index.md => example.com/posts/post-one/
content/about.md => example.com/about/
content/about/index.md => example.com/about/
-
[directory]: its value can be- derived from
.Type1 "_default": default
- derived from
-
filename: its value can be- derived from
layoutset in the frontmatter. "single": default
- derived from
See above for #1, #4, #5, #6
taxonomyTerm
content/tags/_index.md => example.com/tags/
[taxonomies]
tag = "tags"
-
[directory]: its value can be- derived from
.Type1 "taxonomy": the actual string"taxonomy"- derived from its singular form (eg
"tag"for above configuration) "_default": default
- derived from
-
filename: its value can be- derived from
layoutset in the frontmatter. - derived from
<singular> . terms(eg"tag.terms"for above config) "terms": the string"terms""list": default
- derived from
See above for #1, #4, #5, #6
taxonomy
content/tags/foo/_index.md => example.com/tags/foo/
[taxonomies]
tag = "tags"
-
[directory]: its value can be- derived from
.Type1 "taxonomy": the actual string"taxonomy"- derived from the singular form of its term (eg
"tag"for above configuration) "_default": default
- derived from
-
filename: its value can be- derived from
layoutset in the frontmatter. - derived from
<singular>term (eg"tag"for above config) "taxonomy": the string"taxonomy""list": default
- derived from
See above for #1, #4, #5, #6
Some examples
Below are some examples of the effects of values of the above criteria on the layout template used.
Click « on the right to expand the info panel to see these values.
-
for
homepage.Kind(example.com/) -
for
page.Kind(single pages, ieexample.com/posts/lorem-ipsum/) -
for
section.Kind(list pages, ieexample.com/posts/) -
for
taxonomyTerm.Kind(ieexample.com/tags/) -
for
taxonomy.Kind(ieexample.com/tags/tag-one/) -
Other examples
- for single pages (top level, ie
example.com/lorem/) - single page with
ampoutput format #1 - single page with
ampoutput format #2
- for single pages (top level, ie
Minimum example
Hugo can generate your entire site with just two template files:
_default/list.html_default/single.html
You can see this in action by running Hugo with the included minconfig.toml configuration:
hugo server --config minconfig
Multilingual example
This site is configured multilingual by content directory
,
with English being the default language and Latin
a second one. Latin content files are under the /lorem/ content directory.
/metals/
and /la/metals/
both have layout: customlayout in their frontmatter.
/metals/useslayouts/metals/customlayout.html(<type> / <customlayout> . <suffix>)/la/metals/useslayouts/metals/customlayout.la.html(<type> / <customlayout> . <lang> . <suffix>)
Extra examples
-
Section
lorem/_index.mdhascustomtype.- What layout will children pages / sections use?
-
child pages
lorem/ipsum.mdwill have.Type=lorem3See examples:
content/fruit/_index.md:type: customtype=>.Type=customtypecontent/fruit/banana.md:.Type=fruit
-
child section
lorem/ipsum/_index.mdwill have.Type=lorem3See examples:
content/fruit/_index.md:type: customtype=>.Type=customtypecontent/fruit/berries/_index.md:.Type=fruit
-
- How do I make children pages / sections also have
customtypetype?-
Use
cascadein the frontmatter to make the child pages inherit the same value. Alternatively, set thetypeof each content you wantcustomtypeto apply to.Try the
cascadeoption by renaming the frontmatter ofcontent/fruit/_index.mdfromx_cascade:tocascade:.
-
- What layout will children pages / sections use?
-
Section
lorem/_index.mdhascustomlayout-
child pages
lorem/ipsum.mdwill not usecustomlayout3See examples:
content/metals/_index.md:layout: customlayout=> layout =metals/customlayout.htmlcontent/metals/gold.md: layout =_default/single.html
-
Similar to the above, you can
cascadethelayoutfrontmatter so the child pages inherit the same value. Otherwise, you can set the value to each content individually.Try the
cascadeoption by renaming the frontmatter ofcontent/fruit/_index.mdfromx_cascade:tocascade:.
-
Notes:
Some Page Vars
| DOT (.) | Page(/layout-lookup.md) |
| .File | layout-lookup.md |
| .Kind | page |
| .Type | page |
| .Section | |
| .Sections | |
| .Parent | Page(/_index.md) |
| .IsPage | true |
| .IsNode | false |
| .Pages | |
| .Resources | false |
Content Structure
- Circle circle/index.md
- Clouds clouds/_index.md
-
Colors
colors/_index.md
- Blue Title colors/blue/index.md
- Green Title colors/green.md
- Orange Title colors/orange/index.md
- Red Title colors/red.md
- Yellow Title colors/yellow/index.md
- Crescent crescent/index.md
- Ellipse ellipse/index.md
-
Fruit
fruit/_index.md
- Banana fruit/banana.md
-
Berries
fruit/berries/_index.md
- Blackberries fruit/berries/blackberries/index.md
- Blueberries fruit/berries/blueberries/index.md
- Raspberries fruit/berries/raspberries.md
- Strawberries fruit/berries/strawberries/index.md
- Citrus fruit/citrus/_index.md
-
Stonefruit
fruit/stonefruit/_index.md
- Apricots fruit/stonefruit/apricots.md
- Nectarines fruit/stonefruit/nectarines.md
- Plums fruit/stonefruit/plums.md
- Layout Lookup Order layout-lookup.md
- Letters letters/_index.md
- Metals metals/_index.md
- Oval oval/index.md
- Page Resources page-resources.md
- Rectangle rectangle.md
- Rhombus rhombus.md
- Single vs List single-vs-list.md
- Square square.md
- Trapezoid trapezoid.md
- Trees trees/_index.md
Sibling Sections (.Parent.Sections)
| Page | Title | File |
|---|---|---|
| Page(/clouds/_index.md) | Clouds | clouds/_index.md |
| Page(/colors/_index.md) | Colors | colors/_index.md |
| Page(/fruit/_index.md) | Fruit | fruit/_index.md |
| Page(/letters/_index.md) | Letters | letters/_index.md |
| Page(/metals/_index.md) | Metals | metals/_index.md |
| Page(/trees/_index.md) | Trees | trees/_index.md |