diff --git a/include/service/entities/template_service.js b/include/service/entities/template_service.js index 430d2876d..80a1f9f35 100755 --- a/include/service/entities/template_service.js +++ b/include/service/entities/template_service.js @@ -631,6 +631,42 @@ module.exports = function(pb) { return true; }; + /** + * Takes in the below parameters and returns a single TemplateValue that is the combination of + * all items in list, after being ran through the renderFunction. + * + * @param list - The list of data to be used + * @param renderFunction - A function that each item in the list will be ran against + * @param cb - yields error if one occurred, or a single TemplateValue that is the join of + * all values that were returned by the render function + * @returns {*} + */ + TemplateService.prototype.registerLocalForEach = function (list, renderFunction, processFunc, cb) { + // Handle Optional processFunction + if(!cb){ + cb = processFunc; + processFunc = function(e) {return e;}; + } + + if (!list) { + return cb(null, ''); + } + else if (!util.isArray(list)) { + list = [list]; + } + + var tasks = pb.util.getTasks(list, function (item, i) { + return function (callback) { + renderFunction(item[i], callback); + }; + }); + + async.parallel(tasks, function (err, results) { + results = processFunc(results); + cb(err, new pb.TemplateValue(results.join(''), false)); + }); + }; + /** * Registers a model with the template service. It processes each * key/value pair in the object and creates a dot notated string