HUGO
Menu
GitHub 87548 stars Mastodon

Title

返回给定资源的标题(如在 front matter 中所定义),或回退到相对路径或哈希文件名,具体取决于资源类型。

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
---
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 }}

Last updated: January 1, 0001
Improve this page