Params
返回站點配置中定義的自定義參數映射。
Syntax
SITE.Params
Returns
maps.Params
使用此站點配置:
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: The Best Widgets on Earth
[params]
copyright-year = '2023'
subtitle = 'The Best Widgets on Earth'
[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": "The Best Widgets on Earth"
}
}
{{ .Site.Params.subtitle }} → The Best Widgets on Earth
{{ .Site.Params.author.name }} → John Smith
{{ $layout := .Site.Params.layouts.rfc_1123 }}
{{ .Site.Lastmod.Format $layout }} → Tue, 17 Oct 2023 13:21:02 PDT在上面的模板示例中,每個鍵都是有效的標識符。例如,沒有鍵包含連字符。要訪問不是有效標識符的鍵,請使用 index 函數:
{{ index .Site.Params "copyright-year" }} → 2023