HUGO
Menu
GitHub 87548 stars Mastodon

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

Last updated: January 1, 0001
Improve this page