Debian Codegraph @

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

raw
1 ---
2 title: Title
3 description: Returns the title of the given resource as optionally defined in front matter, falling back to a relative path or hashed file name depending on resource type.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: string
9 signatures: [RESOURCE.Title]
10 ---
11
12 The value returned by the `Title` method on a `Resource` object depends on the resource type.
13
14 ## Global resource
15
16 With a [global resource](g), the `Title` method returns the path to the resource, relative to the `assets` directory.
17
18 ```tree
19 assets/
20 └── images/
21 └── Sunrise in Bryce Canyon.jpg
22 ```
23
24 ```go-html-template
25 {{ with resources.Get "images/Sunrise in Bryce Canyon.jpg" }}
26 {{ .Title }} → /images/Sunrise in Bryce Canyon.jpg
27 {{ end }}
28 ```
29
30 ## Page resource
31
32 With a [page resource](g), if you create an element in the `resources` array in front matter, the `Title` method returns the value of the `title` parameter.
33
34 ```tree
35 content/
36 ├── example/
37 │ ├── images/
38 │ │ └── a.jpg
39 │ └── index.md
40 └── _index.md
41 ```
42
43 {{< code-toggle file=content/example/index.md fm=true >}}
44 title = 'Example'
45 [[resources]]
46 src = 'images/a.jpg'
47 title = 'A beautiful sunrise in Bryce Canyon'
48 {{< /code-toggle >}}
49
50 ```go-html-template
51 {{ with .Resources.Get "images/a.jpg" }}
52 {{ .Title }} → A beautiful sunrise in Bryce Canyon
53 {{ end }}
54 ```
55
56 If you do not create an element in the `resources` array in front matter, the `Title` method returns the file path, relative to the page bundle.
57
58 ```tree
59 content/
60 ├── example/
61 │ ├── images/
62 │ │ └── Sunrise in Bryce Canyon.jpg
63 │ └── index.md
64 └── _index.md
65 ```
66
67 ```go-html-template
68 {{ with .Resources.Get "Sunrise in Bryce Canyon.jpg" }}
69 {{ .Title }} → images/Sunrise in Bryce Canyon.jpg
70 {{ end }}
71 ```
72
73 ## Remote resource
74
75 With a [remote resource](g), the `Title` method returns a hashed file name.
76
77 ```go-html-template
78 {{ with resources.GetRemote "https://example.org/images/a.jpg" }}
79 {{ .Title }} → /a_18432433023265451104.jpg
80 {{ end }}
81 ```