github.com/rabbouni145/gg@v0.47.1/docs/content/en/hugo-pipes/resource-from-string.md (about)

     1  ---
     2  title: Creating a resource from a string
     3  linkTitle: Resource from String
     4  description: Hugo Pipes allows the creation of a resource from a string.
     5  date: 2018-07-14
     6  publishdate: 2018-07-14
     7  lastmod: 2018-07-14
     8  categories: [asset management]
     9  keywords: []
    10  menu:
    11    docs:
    12      parent: "pipes"
    13      weight: 90
    14  weight: 90
    15  sections_weight: 90
    16  draft: false
    17  ---
    18  
    19  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.
    20  
    21  The following example creates a resource file containing localized variables for every project's languages.
    22  
    23  ```go-html-template
    24  {{ $string := (printf "var rootURL: '%s'; var apiURL: '%s';" (absURL "/") (.Param "API_URL")) }}
    25  {{ $targetPath := "js/vars.js" }}
    26  {{ $vars := $string | resources.FromString $targetPath }}
    27  {{ $global := resources.Get "js/global.js" | resources.Minify }}
    28  
    29  <script type="text/javascript" src="{{ $vars.Permalink }}"></script>
    30  <script type="text/javascript" src="{{ $global.Permalink }}"></script>
    31  ```