Debian Codegraph @

docs/content/en/methods/page/Resources.md

raw
1 ---
2 title: Resources
3 description: Returns a collection of page resources.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: resource.Resources
9 signatures: [PAGE.Resources]
10 ---
11
12 The `Resources` method on a `Page` object returns a collection of page resources. A page resource is a file within a [page bundle](g).
13
14 To work with global or remote resources, see the [`resources`][] functions.
15
16 ## Methods
17
18 Use these methods on the `Resources` object.
19
20 `ByType`
21 : (`resource.Resources`) Returns a collection of page resources of the given [media type][], or nil if none found. The media type is typically one of `image`, `text`, `audio`, `video`, or `application`.
22
23 ```go-html-template
24 {{ range .Resources.ByType "image" }}
25 <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
26 {{ end }}
27 ```
28
29 When working with global resources instead of page resources, use the [`resources.ByType`][] function.
30
31 `Get`
32 : (`resource.Resource`) Returns a page resource from the given path, or nil if none found.
33
34 ```go-html-template
35 {{ with .Resources.Get "images/a.jpg" }}
36 <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
37 {{ end }}
38 ```
39
40 When working with global resources instead of page resources, use the [`resources.Get`][] function.
41
42 `GetMatch`
43 : (`resource.Resource`) Returns the first page resource from paths matching the given [glob pattern](g), or nil if none found.
44
45 ```go-html-template
46 {{ with .Resources.GetMatch "images/*.jpg" }}
47 <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
48 {{ end }}
49 ```
50
51 When working with global resources instead of page resources, use the [`resources.GetMatch`][] function.
52
53 `Match`
54 : (`resource.Resources`) Returns a collection of page resources from paths matching the given [glob pattern](g), or nil if none found.
55
56 ```go-html-template
57 {{ range .Resources.Match "images/*.jpg" }}
58 <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
59 {{ end }}
60 ```
61
62 When working with global resources instead of page resources, use the [`resources.Match`][] function.
63
64 `Mount`
65 : {{< new-in 0.140.0 />}}
66 : (`ResourceGetter`) Mounts the given resources from the two arguments base (`string`) to the given target path (`string`) and returns an object that implements [Get](#get). Note that leading slashes in target marks an absolute path. Relative target paths allows you to mount resources relative to another set, e.g. a [Page bundle][]:
67
68 ```go-html-template
69 {{ $common := resources.Match "/js/headlessui/*.*" }}
70 {{ $importContext := (slice $.Page ($common.Mount "/js/headlessui" ".")) }}
71 ```
72
73 This method is currently only useful when using the [`js.Batch`][] function.
74
75 ## Pattern matching
76
77 With the `GetMatch` and `Match` methods, Hugo determines a match using a case-insensitive [glob pattern](g).
78
79 {{% include "/_common/glob-patterns.md" %}}
80
81 [Page bundle]: /content-management/page-bundles/
82 [`js.Batch`]: /functions/js/batch/#import-context
83 [`resources.ByType`]: /functions/resources/bytype/
84 [`resources.GetMatch`]: /functions/resources/getmatch/
85 [`resources.Get`]: /functions/resources/get/
86 [`resources.Match`]: /functions/resources/match/
87 [`resources`]: /functions/resources/
88 [media type]: https://en.wikipedia.org/wiki/Media_type