Resources.md - hugo - [fork] hugo port for 9front
HTML git clone https://git.drkhsh.at/hugo.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
Resources.md (3200B)
---
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 ### ByType
19
20 (`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`.
21
22 ```go-html-template
23 {{ range .Resources.ByType "image" }}
24 <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
25 {{ end }}
26 ```
27
28 When working with global resources instead of page resources, use the [`resources.ByType`] function.
29
30 ### Get
31
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
44 (`resource.Resource`) Returns the first page resource from paths matching the given [glob](g) pattern, or nil if none found.
45
46 ```go-html-template
47 {{ with .Resources.GetMatch "images/*.jpg" }}
48 <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
49 {{ end }}
50 ```
51
52 When working with global resources instead of page resources, use the [`resources.GetMatch`] function.
53
54 ### Match
55
56 (`resource.Resources`) Returns a collection of page resources from paths matching the given [glob](g) pattern, or nil if none found.
57
58 ```go-html-template
59 {{ range .Resources.Match "images/*.jpg" }}
60 <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
61 {{ end }}
62 ```
63
64 When working with global resources instead of page resources, use the [`resources.Match`] function.
65
66 ### Mount
67
68 {{< new-in 0.140.0 />}}
69
70 (`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](/content-management/page-bundles/):
71
72 ```go-html-template
73 {{ $common := resources.Match "/js/headlessui/*.*" }}
74 {{ $importContext := (slice $.Page ($common.Mount "/js/headlessui" ".")) }}
75 ```
76
77 This method is currently only useful in [js.Batch](/functions/js/batch/#import-context).
78
79 ## Pattern matching
80
81 With the `GetMatch` and `Match` methods, Hugo determines a match using a case-insensitive [glob](g) pattern.
82
83 {{% include "/_common/glob-patterns.md" %}}
84
85 [`resources.ByType`]: /functions/resources/ByType/
86 [`resources.GetMatch`]: /functions/resources/ByType/
87 [`resources.Get`]: /functions/resources/ByType/
88 [`resources.Match`]: /functions/resources/ByType/
89 [`resources`]: /functions/resources/
90 [media type]: https://en.wikipedia.org/wiki/Media_type