hugo/docs/content/en/methods/resource/Params.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
2024-01-27 10:48:57 +01:00

1.5 KiB

title description categories keywords action
Params Returns a map of resource parameters as defined in front matter.
related returnType signatures
map
RESOURCE.Params

Use the Params method with page resources. It is not applicable to either global or remote resources.

With this content structure:

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

And this front matter:

{{< code-toggle file=content/posts/cats.md fm=true >}} title = 'Cats' resources src = 'images/a.jpg' title = 'Felix the cat' [resources.params] alt = 'Photograph of black cat' temperament = 'vicious' {{< /code-toggle >}}

And this template:

{{ 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 renders:

<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>

See the page resources section for more information.