Params
Syntax
RESOURCE.Params
Returns
map
使用 Params 方法与页面资源一起使用。它不适用于全局资源或远程资源。
以下是内容结构示例:
content/
├── posts/
│   ├── cats/
│   │   ├── images/
│   │   │   └── a.jpg
│   │   └── index.md
│   └── _index.md
└── _index.md
以下是前置元数据示例:
        content/posts/cats.md
      
      
       
      
       
      
       
  ---
resources:
- params:
    alt: 黑猫的照片
    temperament: 凶猛
  src: images/a.jpg
  title: Felix the cat
title: Cats
---+++
title = 'Cats'
[[resources]]
  src = 'images/a.jpg'
  title = 'Felix the cat'
  [resources.params]
    alt = '黑猫的照片'
    temperament = '凶猛'
+++{
   "resources": [
      {
         "params": {
            "alt": "黑猫的照片",
            "temperament": "凶猛"
         },
         "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 }} 是 {{ .Params.temperament }}</figcaption>
  </figure>
{{ end }}
Hugo 渲染结果:
<figure>
  <img alt="黑猫的照片" src="/posts/post-1/images/a.jpg" width="600" height="400">
  <figcaption>Felix the cat 是 凶猛</figcaption>
</figure>
详细信息请参阅页面资源部分。