lookup-order.md (3398B)
1 --- 2 title: Hugo's Lookup Order 3 linktitle: Template Lookup Order 4 description: Hugo searches for the layout to use for a given page in a well defined order, starting from the most specific. 5 date: 2017-02-01 6 publishdate: 2017-02-01 7 lastmod: 2017-07-05 8 categories: [templates,fundamentals] 9 keywords: [templates] 10 menu: 11 docs: 12 parent: "templates" 13 weight: 15 14 quicklinks: 15 weight: 15 16 sections_weight: 15 17 draft: false 18 aliases: [/templates/lookup/] 19 toc: true 20 --- 21 22 ## Hugo Layouts Lookup Rules 23 24 Hugo takes the parameters listed below into consideration when choosing a layout for a given page. They are listed in a priority order. This should feel natural, but look at the table below for concrete examples of the different parameter variations. 25 26 27 Kind 28 : The page `Kind` (the home page is one). See the example tables below per kind. This also determines if it is a **single page** (i.e. a regular content page. We then look for a template in `_default/single.html` for HTML) or a **list page** (section listings, home page, taxonomy lists, taxonomy terms. We then look for a template in `_default/list.html` for HTML). 29 30 Layout 31 : Can be set in page front matter. 32 33 Output Format 34 : See [Custom Output Formats](/templates/output-formats). An output format has both a `name` (e.g. `rss`, `amp`, `html`) and a `suffix` (e.g. `xml`, `html`). We prefer matches with both (e.g. `index.amp.html`, but look for less specific templates. 35 36 Note that if the output format's Media Type has more than one suffix defined, only the first is considered. 37 38 Language 39 : We will consider a language code in the template name. If the site language is `fr`, `index.fr.amp.html` will win over `index.amp.html`, but `index.amp.html` will be chosen before `index.fr.html`. 40 41 Type 42 : Is value of `type` if set in front matter, else it is the name of the root section (e.g. "blog"). It will always have a value, so if not set, the value is "page". 43 44 Section 45 : Is relevant for `section`, `taxonomy` and `term` types. 46 47 {{% note %}} 48 **Tip:** The examples below look long and complex. That is the flexibility talking. Most Hugo sites contain just a handful of templates: 49 50 ```bash 51 ├── _default 52 │ ├── baseof.html 53 │ ├── list.html 54 │ └── single.html 55 └── index.html 56 ``` 57 {{% /note %}} 58 59 60 ## Hugo Layouts Lookup Rules With Theme 61 62 In Hugo, layouts can live in either the project's or the themes' layout folders, and the most specific layout will be chosen. Hugo will interleave the lookups listed below, finding the most specific one either in the project or themes. 63 64 ## Examples: Layout Lookup for Regular Pages 65 66 {{< datatable-filtered "output" "layouts" "Kind == page" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}} 67 68 ## Examples: Layout Lookup for Home Page 69 70 {{< datatable-filtered "output" "layouts" "Kind == home" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}} 71 72 ## Examples: Layout Lookup for Section Pages 73 74 {{< datatable-filtered "output" "layouts" "Kind == section" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}} 75 76 ## Examples: Layout Lookup for Taxonomy Pages 77 78 {{< datatable-filtered "output" "layouts" "Kind == taxonomy" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}} 79 80 ## Examples: Layout Lookup for Term Pages 81 82 {{< datatable-filtered "output" "layouts" "Kind == term" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}}