Content

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