HUGO
Menu
GitHub 87548 stars Mastodon

Params

返回 front matter 中定義的資源參數映射。

Syntax

RESOURCE.Params

Returns

map

頁面資源 使用 Params 方法。它不適用於 全局資源遠程資源

使用此內容結構:

content/
├── posts/
│   ├── cats/
│   │   ├── images/
│   │   │   └── a.jpg
│   │   └── index.md
│   └── _index.md
└── _index.md

和此 front matter:

---
resources:
- params:
    alt: Photograph of black cat
    temperament: vicious
  src: images/a.jpg
  title: Felix the cat
title: Cats
---
+++
title = 'Cats'
[[resources]]
  src = 'images/a.jpg'
  title = 'Felix the cat'
  [resources.params]
    alt = 'Photograph of black cat'
    temperament = 'vicious'
+++
{
   "resources": [
      {
         "params": {
            "alt": "Photograph of black cat",
            "temperament": "vicious"
         },
         "src": "images/a.jpg",
         "title": "Felix the cat"
      }
   ],
   "title": "Cats"
}

和此模板:

{{ with .Resources.Get "images/a.jpg" }}
  <figure>
    <img alt="{{ .Params.alt }}" src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}">
    <figcaption>{{ .Title }} is {{ .Params.temperament }}</figcaption>
  </figure>
{{ end }}

Hugo 渲染為:

<figure>
  <img alt="Photograph of black cat" src="/posts/post-1/images/a.jpg" width="600" height="400">
  <figcaption>Felix the cat is vicious</figcaption>
</figure>

有關更多信息,請參閱 頁面資源 部分。


Last updated: January 1, 0001
Improve this page