Name

Name


Returns the name of the given resource as optionally defined in front matter, falling back to its file path.

The value returned by the Name method on a Resource object depends on the resource type.

Global resource #

With a [global resource], the Name method returns the path to the resource, relative to the assets directory.

assets/
└── images/
    └── Sunrise in Bryce Canyon.jpg
{{ with resources.Get "images/Sunrise in Bryce Canyon.jpg" }}
  {{ .Name }} → /images/Sunrise in Bryce Canyon.jpg
{{ end }}

Page resource #

With a [page resource], if you create an element in the resources array in front matter, the Name method returns the value of the name parameter.

content/
├── example/
│   ├── images/
│   │   └── a.jpg
│   └── index.md
└── _index.md
content/example/index.md
     
---
resources:
- name: Sunrise in Bryce Canyon
  src: images/a.jpg
title: Example
---
+++
title = 'Example'
[[resources]]
  name = 'Sunrise in Bryce Canyon'
  src = 'images/a.jpg'
+++
{
   "resources": [
      {
         "name": "Sunrise in Bryce Canyon",
         "src": "images/a.jpg"
      }
   ],
   "title": "Example"
}
{{ with .Resources.Get "images/a.jpg" }}
  {{ .Name }} → Sunrise in Bryce Canyon
{{ end }}

You can also capture the image by specifying its name instead of its path:

{{ with .Resources.Get "Sunrise in Bryce Canyon" }}
  {{ .Name }} → Sunrise in Bryce Canyon
{{ end }}

If you do not create an element in the resources array in front matter, the Name method returns the file path, relative to the page bundle.

content/
├── example/
│   ├── images/
│   │   └── Sunrise in Bryce Canyon.jpg
│   └── index.md
└── _index.md
{{ with .Resources.Get "images/Sunrise in Bryce Canyon.jpg" }}
  {{ .Name }} → images/Sunrise in Bryce Canyon.jpg
{{ end }}

Remote resource #

With a [remote resource], the Name method returns a hashed file name.

{{ with resources.GetRemote "https://example.org/images/a.jpg" }}
  {{ .Name }} → /a_18432433023265451104.jpg
{{ end }}