Params
返回給定頁面 front matter 中定義的自定義參數映射。
Syntax
PAGE.Params
Returns
maps.Params
例如,考慮此 front matter:
---
date: 2023-10-17T15:11:37-07:00
params:
author:
email: jsmith@example.org
name: John Smith
display_related: true
key-with-hyphens: must use index function
title: Annual conference
---+++
date = 2023-10-17T15:11:37-07:00
title = 'Annual conference'
[params]
display_related = true
key-with-hyphens = 'must use index function'
[params.author]
email = 'jsmith@example.org'
name = 'John Smith'
+++{
"date": "2023-10-17T15:11:37-07:00",
"params": {
"author": {
"email": "jsmith@example.org",
"name": "John Smith"
},
"display_related": true,
"key-with-hyphens": "must use index function"
},
"title": "Annual conference"
}
title 和 date 字段是標准 front matter 字段,而其他字段是用戶定義的。
{{ .Params.display_related }} → true
{{ .Params.author.email }} → jsmith@example.org
{{ .Params.author.name }} → John Smith在上面的模板示例中,每個鍵都是有效的標識符。例如,沒有鍵包含連字符。要訪問不是有效標識符的鍵,請使用 index 函數:
{{ index .Params "key-with-hyphens" }} → must use index function