hugo/docs/content/en/functions/encoding/Base64Decode.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
2024-01-27 10:48:57 +01:00

1 KiB

title description categories keywords action aliases
encoding.Base64Decode Returns the base64 decoding of the given content.
aliases related returnType signatures
base64Decode
functions/encoding/Base64Encode
string
encoding.Base64Decode INPUT
/functions/base64Decode
{{ "SHVnbw==" | base64Decode }} → Hugo

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:

https://api.github.com/repos/gohugoio/hugo/readme

To retrieve and render the content:

{{ $u := "https://api.github.com/repos/gohugoio/hugo/readme" }}
{{ with resources.GetRemote $u }}
  {{ with .Err }}
    {{ errorf "%s" . }}
  {{ else }}
    {{ with . | transform.Unmarshal }}
      {{ .content | base64Decode | markdownify }}
    {{ end }}
  {{ end }}
{{ else }}
  {{ errorf "Unable to get remote resource %q" $u }}
{{ end }}