Template helper for reading from the file system. Includes both async and sync versions.
Install with npm
npm i helper-read --save
var read = require('helper-read');
Usage with lodash
var ctx = {read: read.sync};
_.template('<%= read("fixtures/a.txt") %>')(ctx);
//=> 'AAA'
_.template('<%= read("fixtures/b.txt") %>')(ctx);
//=> 'BBB'
Usage with Template
var read = require('helper-read');
var Template = require('template');
var template = new Template();
/**
* Register an engine
*/
template.engine('foo', require('engine-lodash'));
/**
* Register the helper
*/
template.asyncHelper('read', read);
/**
* Add some templates
*/
template.page('abc.foo', '<%= read("fixtures/a.txt") %>');
template.page('xyz.foo', '<%= read("fixtures/b.txt") %>');
/**
* Render the templates
*/
template.render('abc.foo', function (err, contents) {
if (err) console.log(err);
console.log(contents);
//=> 'AAA'
});
template.render('xyz.foo', function (err, contents) {
if (err) console.log(err);
console.log(contents);
//=> 'BBB'
});
Install dev dependencies:
npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Jon Schlinkert
Copyright (c) 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on May 11, 2015.