Title
Syntax
RESOURCE.Title
Returns
string
The value returned by the Title
method on a Resource
object depends on the resource type.
Global resource
With a global resource, the Title
method returns the path to the resource, relative to the assets directory.
assets/
└── images/
└── a.jpg
{{ with resources.Get "images/a.jpg" }}
{{ .Title }} → images/a.jpg
{{ end }}
Page resource
With a page resource, the Title
method returns the path to the resource, relative to the page bundle.
content/
├── posts/
│ ├── post-1/
│ │ ├── images/
│ │ │ └── a.jpg
│ │ └── index.md
│ └── _index.md
└── _index.md
{{ with .Resources.Get "images/a.jpg" }}
{{ .Title }} → images/a.jpg
{{ end }}
If you create an element in the resources
array in front matter, the Title
method returns the value of the title
parameter:
content/posts/post-1.md
---
resources:
- name: cat
params:
temperament: malicious
src: images/a.jpg
title: Felix the cat
title: Post 1
---
+++
title = 'Post 1'
[[resources]]
name = 'cat'
src = 'images/a.jpg'
title = 'Felix the cat'
[resources.params]
temperament = 'malicious'
+++
{
"resources": [
{
"name": "cat",
"params": {
"temperament": "malicious"
},
"src": "images/a.jpg",
"title": "Felix the cat"
}
],
"title": "Post 1"
}
{{ with .Resources.Get "cat" }}
{{ .Title }} → Felix the cat
{{ end }}
If the page resource is a content file, the Title
methods return the title
field as defined in front matter.
content/
├── lessons/
│ ├── lesson-1/
│ │ ├── _objectives.md <-- resource type = page
│ │ └── index.md
│ └── _index.md
└── _index.md
Remote resource
With a remote resource, the Title
method returns a hashed file name.
{{ with resources.GetRemote "https://example.org/images/a.jpg" }}
{{ .Title }} → a_18432433023265451104.jpg
{{ end }}