Debian Codegraph @

docs/content/en/functions/encoding/Base64Decode.md

raw
1 ---
2 title: encoding.Base64Decode
3 description: Returns the base64 decoding of the given content.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 aliases: [base64Decode]
9 returnType: string
10 signatures: [encoding.Base64Decode INPUT]
11 aliases: [/functions/base64Decode]
12 ---
13
14 ```go-html-template
15 {{ "SHVnbw==" | base64Decode }} → Hugo
16 ```
17
18 Use the `base64Decode` function to decode responses from APIs. For example, the result of this call to GitHub's API contains the base64-encoded representation of the repository's README file:
19
20 ```text
21 https://api.github.com/repos/gohugoio/hugo/readme
22 ```
23
24 To retrieve and render the content:
25
26 ```go-html-template
27 {{ $url := "https://api.github.com/repos/gohugoio/hugo/readme" }}
28 {{ with try (resources.GetRemote $url) }}
29 {{ with .Err }}
30 {{ errorf "%s" . }}
31 {{ else with .Value }}
32 {{ with . | transform.Unmarshal }}
33 {{ .content | base64Decode | markdownify }}
34 {{ end }}
35 {{ else }}
36 {{ errorf "Unable to get remote resource %q" $url }}
37 {{ end }}
38 {{ end }}
39 ```