summaryrefslogtreecommitdiffstats
path: root/docs/content/en/methods/resource/Params.md
blob: 38f2ef6c27e54f61553951e5c207db8f34000cc6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
---
title: Params
description: Returns a map of resource parameters as defined in front matter.
categories: []
keywords: []
params:
  functions_and_methods:
    returnType: map
    signatures: [RESOURCE.Params]
---

Use the `Params` method with [page resources](g). It is not applicable to either [global resources](g) or [remote resources](g).

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>
    <img alt="{{ .Params.alt }}" src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}">
    <figcaption>{{ .Title }} is {{ .Params.temperament }}</figcaption>
  </figure>
{{ end }}
```

Hugo renders:

```html
<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.

[page resources]: /content-management/page-resources/