Title

Title 方法

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

頁面資源

對於 頁面資源,如果你在前置資料中的 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 }}

如果你沒有在前置資料中的 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 }}