Params
Syntax
SITE.Params
Returns
maps.Params
使用以下网站配置:
hugo.
params:
author:
email: jsmith@example.org
name: John Smith
copyright-year: "2023"
layouts:
rfc_1123: Mon, 02 Jan 2006 15:04:05 MST
rfc_3339: "2006-01-02T15:04:05-07:00"
subtitle: 地球上最好的小工具
[params]
copyright-year = '2023'
subtitle = '地球上最好的小工具'
[params.author]
email = 'jsmith@example.org'
name = 'John Smith'
[params.layouts]
rfc_1123 = 'Mon, 02 Jan 2006 15:04:05 MST'
rfc_3339 = '2006-01-02T15:04:05-07:00'
{
"params": {
"author": {
"email": "jsmith@example.org",
"name": "John Smith"
},
"copyright-year": "2023",
"layouts": {
"rfc_1123": "Mon, 02 Jan 2006 15:04:05 MST",
"rfc_3339": "2006-01-02T15:04:05-07:00"
},
"subtitle": "地球上最好的小工具"
}
}
{{ .Site.Params.subtitle }} → 地球上最好的小工具
{{ .Site.Params.author.name }} → John Smith
{{ $layout := .Site.Params.layouts.rfc_1123 }}
{{ .Site.LastChange.Format $layout }} → Tue, 17 Oct 2023 13:21:02 PDT
在上述模板示例中,每个键都是一个有效的标识符。例如,键中都不含连字符。要访问非有效标识符的键,使用index
函数:
{{ index .Site.Params "copyright-year" }} → 2023