Params
语法
PAGE.Params
返回
maps.Params
使用以下前言
content/news/annual-conference.md。
date: 2023-10-17T15:11:37-07:00
params:
author:
email: jsmith@example.org
name: John Smith
display_related: true
title: Annual conference
date = 2023-10-17T15:11:37-07:00
title = 'Annual conference'
[params]
display_related = true
[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
},
"title": "Annual conference"
}
title
和 date
字段是标准参数,其他字段是用户定义的。
{{ .Params.display_related }} → true
{{ .Params.author.name }} → John Smith
在上面的模板示例中,每个键都是有效的标识符。例如,没有一个键包含连字符。要访问不是有效标识符的键,请使用index
函数
{{ index .Params "key-with-hyphens" }} → 2023