| 1 |
--- |
| 2 |
title: Layout |
| 3 |
description: Returns the layout for the given page as defined in front matter. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
returnType: string |
| 9 |
signatures: [PAGE.Layout] |
| 10 |
--- |
| 11 |
|
| 12 |
Specify the `layout` field in front matter to target a particular template. See [details][]. |
| 13 |
|
| 14 |
{{< code-toggle file=content/contact.md fm=true >}} |
| 15 |
title = 'Contact' |
| 16 |
layout = 'contact' |
| 17 |
{{< /code-toggle >}} |
| 18 |
|
| 19 |
Hugo will render the page using contact.html. |
| 20 |
|
| 21 |
```tree |
| 22 |
layouts/ |
| 23 |
├── baseof.html |
| 24 |
├── contact.html |
| 25 |
├── home.html |
| 26 |
├── page.html |
| 27 |
├── section.html |
| 28 |
├── taxonomy.html |
| 29 |
└── term.html |
| 30 |
``` |
| 31 |
|
| 32 |
Although rarely used within a template, you can access the value with: |
| 33 |
|
| 34 |
```go-html-template |
| 35 |
{{ .Layout }} |
| 36 |
``` |
| 37 |
|
| 38 |
The `Layout` method returns an empty string if the `layout` field in front matter is not defined. |
| 39 |
|
| 40 |
[details]: /templates/lookup-order/#target-a-template |