hugo/docs/content/en/hugo-pipes/resource-from-string.md
2022-11-17 16:16:19 +01:00

971 B
Executable file

title linkTitle description date publishdate categories keywords menu weight sections_weight
Creating a resource from a string Resource from String Hugo Pipes allows the creation of a resource from a string. 2018-07-14 2018-07-14
asset management
docs
parent weight
pipes 90
90 90

It is possible to create a resource directly from the template using resources.FromString which takes two arguments, the given string and the resource target path.

The following example creates a resource file containing localized variables for every project's languages.

{{ $string := (printf "var rootURL = '%s'; var apiURL = '%s';" (absURL "/") (.Param "API_URL")) }}
{{ $targetPath := "js/vars.js" }}
{{ $vars := $string | resources.FromString $targetPath }}
{{ $global := resources.Get "js/global.js" | resources.Minify }}

<script src="{{ $vars.Permalink }}"></script>
<script src="{{ $global.Permalink }}"></script>