hugo/docs/content/en/methods/resource/Name.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
2024-01-27 10:48:57 +01:00

2 KiB

title description categories keywords action toc
Name Returns the name of the given resource as optionally defined in front matter, falling back to a relative path or hashed file name depending on resource type.
related returnType signatures
methods/resource/Title
string
RESOURCE.Name
true

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/
    └── a.jpg
{{ with resources.Get "images/a.jpg" }}
  {{ .Name }} → images/a.jpg
{{ end }}

Page resource

With a page resource, the Name 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" }}
  {{ .Name }} → images/a.jpg
{{ end }}

If you create an element in the resources array in front matter, the Name method returns the value of the name parameter:

{{< code-toggle file=content/posts/post-1.md fm=true >}} title = 'Post 1' resources src = 'images/a.jpg' name = 'cat' title = 'Felix the cat' [resources.params] temperament = 'malicious' {{< /code-toggle >}}

{{ with .Resources.Get "cat" }}
  {{ .Name }} →  cat
{{ 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 }}