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