mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-14 19:14:46 -04:00
Update RESOURCE.Name examples
This commit is contained in:
parent
8cf5046f5d
commit
6a4f38fc39
@ -10,7 +10,6 @@ menu:
|
|||||||
weight: 260
|
weight: 260
|
||||||
toc: true
|
toc: true
|
||||||
---
|
---
|
||||||
{{< new-in 0.93.0 >}}
|
|
||||||
|
|
||||||
## GoAT diagrams (ASCII)
|
## GoAT diagrams (ASCII)
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ Adaptation of a site to meet language and regional requirements. This includes t
|
|||||||
|
|
||||||
{{< new-in 0.123.0 >}}
|
{{< new-in 0.123.0 >}}
|
||||||
|
|
||||||
A page or page resource identifier derived from the file path, excluding its extension and language identifier. This value is neither a file path nor a URL. <!-- You may also set this value using the `path` front matter field. --> See [details](/methods/page/path).
|
A page or page resource identifier derived from the file path, excluding its extension and language identifier. This value is neither a file path nor a URL. Starting with a file path relative to the content directory, Hugo determines the logical path by stripping the file extension and language identifier, converting to lower case, then replacing spaces with hyphens. <!-- You may also set this value using the `path` front matter field. --> See [examples](/methods/page/path/#examples).
|
||||||
|
|
||||||
###### map
|
###### map
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ To determine the logical path for pages backed by a file, Hugo starts with the f
|
|||||||
1. Strips the file extension
|
1. Strips the file extension
|
||||||
2. Strips the language identifier
|
2. Strips the language identifier
|
||||||
3. Converts the result to lower case
|
3. Converts the result to lower case
|
||||||
4. Replaces all spaces with hyphens
|
4. Replaces spaces with hyphens
|
||||||
|
|
||||||
The value returned by the `Path` method on a `Page` object is independent of content format, language, and URL modifiers such as the `slug` and `url` front matter fields.
|
The value returned by the `Path` method on a `Page` object is independent of content format, language, and URL modifiers such as the `slug` and `url` front matter fields.
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: Name
|
title: Name
|
||||||
description: 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.
|
description: Returns the name of the given resource as optionally defined in front matter, falling back to its path.
|
||||||
categories: []
|
categories: []
|
||||||
keywords: []
|
keywords: []
|
||||||
action:
|
action:
|
||||||
@ -25,13 +25,31 @@ assets/
|
|||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
{{ with resources.Get "images/a.jpg" }}
|
{{ with resources.Get "images/a.jpg" }}
|
||||||
{{ .Name }} → images/a.jpg
|
{{ .Name }} → /images/a.jpg
|
||||||
{{ end }}
|
{{ end }}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Page resource
|
## Page resource
|
||||||
|
|
||||||
With a [page resource], the `Name` method returns the path to the resource, relative to the page bundle.
|
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:
|
||||||
|
|
||||||
|
{{< 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 >}}
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ with .Resources.Get "cat" }}
|
||||||
|
{{ .Name }} → cat
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
If you do not create an element in the `resources` array in front matter, the `Name` method returns the [logical path] to the resource, relative to the page bundle.
|
||||||
|
|
||||||
```text
|
```text
|
||||||
content/
|
content/
|
||||||
@ -49,34 +67,17 @@ content/
|
|||||||
{{ .Name }} → images/a.jpg
|
{{ .Name }} → images/a.jpg
|
||||||
{{ end }}
|
{{ 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 >}}
|
|
||||||
|
|
||||||
```go-html-template
|
|
||||||
{{ with .Resources.Get "cat" }}
|
|
||||||
{{ .Name }} → cat
|
|
||||||
{{ end }}
|
|
||||||
```
|
|
||||||
## Remote resource
|
## Remote resource
|
||||||
|
|
||||||
With a [remote resource], the `Name` method returns a hashed file name.
|
With a [remote resource], the `Name` method returns a hashed file name.
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
{{ with resources.GetRemote "https://example.org/images/a.jpg" }}
|
{{ with resources.GetRemote "https://example.org/images/a.jpg" }}
|
||||||
{{ .Name }} → a_18432433023265451104.jpg
|
{{ .Name }} → /a_18432433023265451104.jpg
|
||||||
{{ end }}
|
{{ end }}
|
||||||
```
|
```
|
||||||
|
|
||||||
[global resource]: /getting-started/glossary/#global-resource
|
[global resource]: /getting-started/glossary/#global-resource
|
||||||
|
[logical path]: /getting-started/glossary/#logical-path
|
||||||
[page resource]: /getting-started/glossary/#page-resource
|
[page resource]: /getting-started/glossary/#page-resource
|
||||||
[remote resource]: /getting-started/glossary/#remote-resource
|
[remote resource]: /getting-started/glossary/#remote-resource
|
||||||
|
Loading…
x
Reference in New Issue
Block a user