mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-19 10:44:38 -04:00
Revise and improve RESOURCE.Name and RESOURCE.Title examples
This commit is contained in:
parent
4aafbb2f4f
commit
3c103d0f90
@ -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 its path.
|
description: Returns the name of the given resource as optionally defined in front matter, falling back to its file path.
|
||||||
categories: []
|
categories: []
|
||||||
keywords: []
|
keywords: []
|
||||||
action:
|
action:
|
||||||
@ -20,51 +20,63 @@ With a [global resource], the `Name` method returns the path to the resource, re
|
|||||||
```text
|
```text
|
||||||
assets/
|
assets/
|
||||||
└── images/
|
└── images/
|
||||||
└── a.jpg
|
└── Sunrise in Bryce Canyon.jpg
|
||||||
```
|
```
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
{{ with resources.Get "images/a.jpg" }}
|
{{ with resources.Get "images/Sunrise in Bryce Canyon.jpg" }}
|
||||||
{{ .Name }} → /images/a.jpg
|
{{ .Name }} → /images/Sunrise in Bryce Canyon.jpg
|
||||||
{{ end }}
|
{{ end }}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Page resource
|
## 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:
|
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/
|
||||||
├── posts/
|
├── example/
|
||||||
│ ├── post-1/
|
│ ├── images/
|
||||||
│ │ ├── images/
|
│ │ └── a.jpg
|
||||||
│ │ │ └── a.jpg
|
│ └── index.md
|
||||||
│ │ └── index.md
|
└── _index.md
|
||||||
│ └── _index.md
|
```
|
||||||
|
|
||||||
|
{{< code-toggle file=content/example/index.md fm=true >}}
|
||||||
|
title = 'Example'
|
||||||
|
[[resources]]
|
||||||
|
src = 'images/a.jpg'
|
||||||
|
name = 'Sunrise in Bryce Canyon'
|
||||||
|
{{< /code-toggle >}}
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ 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:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ 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.
|
||||||
|
|
||||||
|
```text
|
||||||
|
content/
|
||||||
|
├── example/
|
||||||
|
│ ├── images/
|
||||||
|
│ │ └── Sunrise in Bryce Canyon.jpg
|
||||||
|
│ └── index.md
|
||||||
└── _index.md
|
└── _index.md
|
||||||
```
|
```
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
{{ with .Resources.Get "images/a.jpg" }}
|
{{ with .Resources.Get "images/Sunrise in Bryce Canyon.jpg" }}
|
||||||
{{ .Name }} → images/a.jpg
|
{{ .Name }} → images/Sunrise in Bryce Canyon.jpg
|
||||||
{{ end }}
|
{{ end }}
|
||||||
```
|
```
|
||||||
## Remote resource
|
## Remote resource
|
||||||
|
@ -20,66 +20,58 @@ With a [global resource], the `Title` method returns the path to the resource, r
|
|||||||
```text
|
```text
|
||||||
assets/
|
assets/
|
||||||
└── images/
|
└── images/
|
||||||
└── a.jpg
|
└── Sunrise in Bryce Canyon.jpg
|
||||||
```
|
```
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
{{ with resources.Get "images/a.jpg" }}
|
{{ with resources.Get "images/Sunrise in Bryce Canyon.jpg" }}
|
||||||
{{ .Title }} → images/a.jpg
|
{{ .Title }} → /images/Sunrise in Bryce Canyon.jpg
|
||||||
{{ end }}
|
{{ end }}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Page resource
|
## Page resource
|
||||||
|
|
||||||
With a [page resource], the `Title` 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 `Title` method returns the value of the `title` parameter.
|
||||||
|
|
||||||
```text
|
```text
|
||||||
content/
|
content/
|
||||||
├── posts/
|
├── example/
|
||||||
│ ├── post-1/
|
│ ├── images/
|
||||||
│ │ ├── images/
|
│ │ └── a.jpg
|
||||||
│ │ │ └── a.jpg
|
│ └── index.md
|
||||||
│ │ └── index.md
|
|
||||||
│ └── _index.md
|
|
||||||
└── _index.md
|
└── _index.md
|
||||||
```
|
```
|
||||||
|
|
||||||
```go-html-template
|
{{< code-toggle file=content/example/index.md fm=true >}}
|
||||||
{{ with .Resources.Get "images/a.jpg" }}
|
title = 'Example'
|
||||||
{{ .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:
|
|
||||||
|
|
||||||
{{< code-toggle file=content/posts/post-1.md fm=true >}}
|
|
||||||
title = 'Post 1'
|
|
||||||
[[resources]]
|
[[resources]]
|
||||||
src = 'images/a.jpg'
|
src = 'images/a.jpg'
|
||||||
name = 'cat'
|
title = 'A beautiful sunrise in Bryce Canyon'
|
||||||
title = 'Felix the cat'
|
|
||||||
[resources.params]
|
|
||||||
temperament = 'malicious'
|
|
||||||
{{< /code-toggle >}}
|
{{< /code-toggle >}}
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
{{ with .Resources.Get "cat" }}
|
{{ with .Resources.Get "images/a.jpg" }}
|
||||||
{{ .Title }} → Felix the cat
|
{{ .Title }} → A beautiful sunrise in Bryce Canyon
|
||||||
{{ end }}
|
{{ end }}
|
||||||
```
|
```
|
||||||
|
|
||||||
If the page resource is a content file, the `Title` methods return the `title` field as defined in front matter.
|
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.
|
||||||
|
|
||||||
```text
|
```text
|
||||||
content/
|
content/
|
||||||
├── lessons/
|
├── example/
|
||||||
│ ├── lesson-1/
|
│ ├── images/
|
||||||
│ │ ├── _objectives.md <-- resource type = page
|
│ │ └── Sunrise in Bryce Canyon.jpg
|
||||||
│ │ └── index.md
|
│ └── index.md
|
||||||
│ └── _index.md
|
|
||||||
└── _index.md
|
└── _index.md
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ with .Resources.Get "Sunrise in Bryce Canyon.jpg" }}
|
||||||
|
{{ .Title }} → images/Sunrise in Bryce Canyon.jpg
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
## Remote resource
|
## Remote resource
|
||||||
|
|
||||||
With a [remote resource], the `Title` method returns a hashed file name.
|
With a [remote resource], the `Title` method returns a hashed file name.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user