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