mangony-hbs-helpers
Version:
Handlebars helpers used by Mangony
26 lines (23 loc) • 654 B
JavaScript
/*
* Get Data Helper
* Returns a specific data object from data context
*
* @author Sebastian Fitzner
*/
module.exports = getData;
module.exports.register = function (Handlebars) {
Handlebars.registerHelper('getData', getData);
};
function getData(obj) {
var prefix = obj.hash.typeof + 's';
var context = {};
if (obj.hash.typeof === 'partial' || obj.hash.typeof === 'layout') {
prefix = '__' + obj.hash.typeof + 's';
context = obj.data.root[prefix][obj.hash.from];
} else if (obj.hash.typeof === 'data') {
context = obj.data.root[obj.hash.from];
} else {
context = obj.data.root[prefix][obj.hash.from];
}
return obj.fn(context);
}