标题
Syntax
RESOURCE.Title
Returns
string
Resource
对象的 Title
方法返回的值取决于资源类型。
全局资源
对于 全局资源 , Title
方法返回资源相对于 assets 目录的路径。
assets/
└── images/
└── Sunrise in Bryce Canyon.jpg
{{ with resources.Get "images/Sunrise in Bryce Canyon.jpg" }}
{{ .Title }} → /images/Sunrise in Bryce Canyon.jpg
{{ end }}
页面资源
对于 页面资源 ,如果您在 front matter 中的 resources
数组中创建一个元素,则 Title
方法返回 title
参数的值。
content/
├── example/
│ ├── images/
│ │ └── a.jpg
│ └── index.md
└── _index.md
content/example/index.md
---
resources:
- src: images/a.jpg
title: A beautiful sunrise in Bryce Canyon
title: Example
---
+++
title = 'Example'
[[resources]]
src = 'images/a.jpg'
title = 'A beautiful sunrise in Bryce Canyon'
+++
{
"resources": [
{
"src": "images/a.jpg",
"title": "A beautiful sunrise in Bryce Canyon"
}
],
"title": "Example"
}
{{ with .Resources.Get "images/a.jpg" }}
{{ .Title }} → A beautiful sunrise in Bryce Canyon
{{ end }}
如果您没有在 front matter 中的 resources
数组中创建元素,则 Title
方法返回相对于页面包的文件路径。
content/
├── example/
│ ├── images/
│ │ └── Sunrise in Bryce Canyon.jpg
│ └── index.md
└── _index.md
{{ with .Resources.Get "Sunrise in Bryce Canyon.jpg" }}
{{ .Title }} → images/Sunrise in Bryce Canyon.jpg
{{ end }}
远程资源
对于 远程资源 , Title
方法返回一个哈希文件名。
{{ with resources.GetRemote "https://example.org/images/a.jpg" }}
{{ .Title }} → /a_18432433023265451104.jpg
{{ end }}