mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-01 15:29:10 -05:00
5fd1e74903
``` git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash ``` Closes #11925
1 KiB
Executable file
1 KiB
Executable file
title | linkTitle | description | categories | keywords | menu | weight | action | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
FromString | Resource from string | Creates a resource from a string. |
|
|
110 |
|
Usage
It is possible to create a resource directly from the template using resources.FromString
which takes two arguments, the target path for the created resource and the given content string.
The result is cached using the target path as the cache key.
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>