Layout
返回 front matter 中定義的給定頁面的布局。
Syntax
PAGE.Layout
Returns
string
在 front matter 中指定 layout 字段以定位特定模板。詳見 詳情。
---
layout: contact
title: Contact
---+++
layout = 'contact'
title = 'Contact'
+++{
"layout": "contact",
"title": "Contact"
}
Hugo 將使用 contact.html 渲染頁面。
layouts/
├── baseof.html
├── contact.html
├── home.html
├── page.html
├── section.html
├── taxonomy.html
└── term.html雖然很少在模板中使用,但您可以使用以下方式訪問該值:
{{ .Layout }}如果 front matter 中未定義 layout 字段,Layout 方法返回空字符串。