Params
Syntax
PAGE.Params
Returns
maps.Params
使用以下前置元数据:
content/news/annual-conference.md.
date: 2023-10-17T15:11:37-07:00
display_related: true
event-date: "2023"
params:
author:
email: jsmith@example.org
name: John Smith
title: Annual conference
date = 2023-10-17T15:11:37-07:00
display_related = true
event-date = '2023'
title = 'Annual conference'
[params]
[params.author]
email = 'jsmith@example.org'
name = 'John Smith'
{
"date": "2023-10-17T15:11:37-07:00",
"display_related": true,
"event-date": "2023",
"params": {
"author": {
"email": "jsmith@example.org",
"name": "John Smith"
}
},
"title": "Annual conference"
}
title
和 date
字段是标准参数——其他字段是用户定义的。
{{ .Params.display_related }} → true
{{ .Params.author.name }} → John Smith
在上面的模板示例中,每个键都是一个有效的标识符。例如,没有任何键包含连字符。如果要访问不是有效标识符的键,请使用index
函数:
{{ index .Params "event-date" }} → 2023