Page

Params

返回给定页面前置元数据中定义的自定义参数映射。

签名
PAGE.Params
返回类型
maps.Params

举例来说,考虑下面这段前置元数据:

title = 'Annual conference'
date = 2023-10-17T15:11:37-07:00
[params]
display_related = true
key-with-hyphens = 'must use index function'
[params.author]
  email = 'jsmith@example.org'
  name = 'John Smith'

title 和 date 是标准的[前置元数据字段][],其余字段则由用户自定义。

需要时,可以通过链式书写标识符来访问这些自定义字段:

{{ .Params.display_related }} → true
{{ .Params.author.email }} → jsmith@example.org
{{ .Params.author.name }} → John Smith

在上面的模板示例中,每个 key 都是合法的标识符。例如,没有一个 key 含连字符。要访问不是合法标识符的 key,请使用 index 函数:

{{ index .Params "key-with-hyphens" }} → must use index function