Params
返回前置元数据中定义的资源参数映射。
Params 方法用于page resource(页面资源),不适用于global resource(全局资源)或remote resource(远程资源)。
有如下内容结构:
content/
├── posts/
│ ├── cats/
│ │ ├── images/
│ │ │ └── a.jpg
│ │ └── index.md
│ └── _index.md
└── _index.md以及如下前置元数据:
title = 'Cats'
[[resources]]
src = 'images/a.jpg'
title = 'Felix the cat'
[resources.params]
alt = 'Photograph of black cat'
temperament = 'vicious'以及这个模板:
{{ 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>更多信息请参见页面资源一节。