hugo/content/en/hugo-pipes/resource-from-string.md
Bjørn Erik Pedersen a3535c8486 Squashed 'docs/' changes from cfe89ecbc..a4fa0d1d6
a4fa0d1d6 Typos and grammatical changes
513884600 Add hugo pipes documentation

git-subtree-dir: docs
git-subtree-split: a4fa0d1d641b2b3e27a91ae8b1a0a29be3c42ddf
2018-07-19 09:18:11 +02:00

1 KiB
Executable file

title linkTitle description date publishdate lastmod categories keywords menu weight sections_weight draft
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 2018-07-14
asset management
docs
parent weight
pipes 90
90 90 false

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 type="text/javascript" src="{{ $vars.Permalink }}"></script>
<script type="text/javascript" src="{{ $global.Permalink }}"></script>