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