参数
Syntax
PAGE.Params
Returns
maps.Params
使用以下前置内容:
content/news/annual-conference.md.
date: 2023-10-17T15:11:37-07:00
params:
author:
email: [email protected]
name: John Smith
display_related: true
title: 年度会议
date = 2023-10-17T15:11:37-07:00
title = '年度会议'
[params]
display_related = true
[params.author]
email = '[email protected]'
name = 'John Smith'
{
"date": "2023-10-17T15:11:37-07:00",
"params": {
"author": {
"email": "[email protected]",
"name": "John Smith"
},
"display_related": true
},
"title": "年度会议"
}
title
和 date
字段是标准参数——其他字段是用户自定义的。
通过 链式访问 [标识符] 来访问自定义参数:
{{ .Params.display_related }} → true
{{ .Params.author.name }} → John Smith
在上面的模板示例中,每个键都是有效的标识符。例如,没有一个键包含连字符。要访问不是有效标识符的键,请使用 index
函数:
{{ index .Params "key-with-hyphens" }} → 2023