VoteIT

  • News
  • Documentation
  • Members
  • In Swedish
  • Code
Star
ASSET MANAGEMENT

Creating a resource from a string

Hugo Pipes allows the creation of a resource from a string.

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>
  • About VoteIT
    • Overview
    • Hugo and GDPR
    • What is Hugo
    • Bylaws
    • History
    • Hugo Features
    • The Benefits of Static
    • License
  • Getting Started
    • Get Started Overview
    • Quick Start
    • Install Hugo
    • Basic Usage
    • Directory Structure
    • Configuration
  • VoteIT Modules
  • Content Management
  • Templates
  • Functions
  • Variables
  • Hugo Pipes
    • Hugo Pipes Overview
    • Hugo Pipes Introduction
    • SASS / SCSS
    • PostCSS
    • Asset minification
    • Asset bundling
    • Fingerprinting and SRI
    • Resource from Template
    • Resource from String
  • CLI
  • Troubleshooting
  • Tools
  • Hosting & Deployment
  • Contribute
“Creating a resource from a string” was last updated: July 14, 2018
Improve this page
By the VoteIT Authors
VoteIT Logo
  • File an Issue
  • @VoteIT
  • @robin_betahaus
  • @andershultman
 
 

VoteIT Sponsors

Logo for VoteIT
Logo for Betahaus
Logo for Datatrion AB
 

The VoteIT logos are copyright © VoteIT 2011–2020.

  • News
  • Documentation
  • Members
  • In Swedish
  • Code
  • About VoteIT
  • Getting Started
  • VoteIT Modules
  • Content Management
  • Templates
  • Functions
  • Variables
  • Hugo Pipes
  • CLI
  • Troubleshooting
  • Tools
  • Hosting & Deployment
  • Contribute