HUGO
Menu
GitHub 87548 stars Mastodon

Content

返回給定資源的內容。

Syntax

RESOURCE.Content

Returns

any

此方法可用於 全局資源頁面資源遠程資源

Resource 對象上的 Content 方法在 資源類型page 時返回 template.HTML,否則返回 string

assets/quotations/kipling.txt
He travels the fastest who travels alone.

要獲取內容:

{{ with resources.Get "quotations/kipling.txt" }}
  {{ .Content }} → He travels the fastest who travels alone.
{{ end }}

要獲取字節大小:

{{ with resources.Get "quotations/kipling.txt" }}
  {{ .Content | len }} → 42
{{ end }}

要創建內聯圖像:

{{ with resources.Get "images/a.jpg" }}
  <img src="data:{{ .MediaType.Type }};base64,{{ .Content | base64Encode }}">
{{ end }}

要創建內聯 CSS:

{{ with resources.Get "css/style.css" }}
  <style>{{ .Content | safeCSS }}</style>
{{ end }}

要創建內聯 JavaScript:

{{ with resources.Get "js/script.js" }}
  <script>{{ .Content | safeJS }}</script>
{{ end }}

Last updated: January 1, 0001
Improve this page