const resolve = require('{%= name %}');
const Handlebars = require('handlebars');
handlebars.registerHelper('resolve', function (name, key) {
return resolve.sync(fp)[typeof key === 'string' ? key : 'main'];
});
handlebars.compile('<script src=\"{{resolve "jquery" "main"}}\"></script>')();
//=> '<script src="node_modules/jquery/dist/jquery.js"></script>'
handlebars.compile('{{resolve "jquery" "homepage"}}')();
//=> 'http://jquery.com'
Register the helper with [assemble] v0.6.x to use with any template engine:
const assemble = require('assemble');
assemble.helper('resolve', function (name, key) {
return resolve.sync(fp)[typeof key === 'string' ? key : 'main'];
});
async helper
assemble.asyncHelper('resolve', function (name, key, cb) {
if (typeof key === 'function') {
cb = key;
key = 'main';
}
resolve(name, function (err, res) {
cb(null, res[key]);
});
});