Improve inline resource examples (#1587)

This commit is contained in:
Joe Mooring 2021-11-30 08:24:56 -08:00 committed by GitHub
parent 2eae7c7ec0
commit 8262b077c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,7 +60,22 @@ RelPermalink
: The relative URL to the resource. Resources of type `page` will have no value.
Content
: The content of the resource itself. For most resources, this returns a string with the contents of the file. This can be used to inline some resources, such as `<script>{{ (.Resources.GetMatch "myscript.js").Content | safeJS }}</script>` or `<img src="{{ (.Resources.GetMatch "mylogo.png").Content | base64Encode }}">`.
: The content of the resource itself. For most resources, this returns a string
with the contents of the file. Use this to create inline resources.
```go-html-template
{{ with .Resources.GetMatch "script.js" }}
<script>{{ .Content | safeJS }}</script>
{{ end }}
{{ with .Resources.GetMatch "style.css" }}
<style>{{ .Content | safeCSS }}</style>
{{ end }}
{{ with .Resources.GetMatch "img.png" }}
<img src="data:{{ .MediaType }};base64,{{ .Content | base64Encode }}">
{{ end }}
```
MediaType
: The MIME type of the resource, such as `image/jpeg`.