HUGO
Menu
GitHub 87548 stars Mastodon

Params

返回给定页面 front matter 中定义的自定义参数映射。

Syntax

PAGE.Params

Returns

maps.Params

例如,考虑此 front matter:

---
date: 2023-10-17T15:11:37-07:00
params:
  author:
    email: jsmith@example.org
    name: John Smith
  display_related: true
  key-with-hyphens: must use index function
title: Annual conference
---
+++
date = 2023-10-17T15:11:37-07:00
title = 'Annual conference'
[params]
  display_related = true
  key-with-hyphens = 'must use index function'
  [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,
      "key-with-hyphens": "must use index function"
   },
   "title": "Annual conference"
}

titledate 字段是标准 front matter 字段,而其他字段是用户定义的。

通过 链式 标识符(需要时)访问自定义字段:

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

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

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

Last updated: January 1, 0001
Improve this page