mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-02 02:49:32 -05:00
29 lines
949 B
Markdown
Executable file
29 lines
949 B
Markdown
Executable file
---
|
|
title: FromString
|
|
linkTitle: Resource from String
|
|
description: Creates a resource from a string.
|
|
categories: [asset management]
|
|
keywords: []
|
|
menu:
|
|
docs:
|
|
parent: pipes
|
|
weight: 90
|
|
weight: 90
|
|
signature: ["resources.FromString TARGET_PATH CONTENT"]
|
|
---
|
|
|
|
## 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 following example creates a resource file containing localized variables for every project's languages.
|
|
|
|
```go-html-template
|
|
{{ $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>
|
|
```
|