Back to Hugo

Params

docs/content/en/methods/resource/Params.md

0.161.11.2 KB
Original Source

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

With this content structure:

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

go-html-template
{{ with .Resources.Get "images/a.jpg" }}
  <figure>
    
    <figcaption>{{ .Title }} is {{ .Params.temperament }}</figcaption>
  </figure>
{{ end }}

Hugo renders:

html
<figure>
  
  <figcaption>Felix the cat is vicious</figcaption>
</figure>

See the page resources section for more information.