Closed benoitdevrieze closed 8 years ago
I have made a mistake. It does work perfectly. The helper code should be:
module.exports.join = function(context, options) {
var delimiter = options.hash.delimiter || ",";
if (options.fn) {
return [].concat(context).slice(start, end).map(options.fn).join(delimiter);
} else {
return [].concat(context).slice(start, end).join(delimiter);
}
}
I want to write a block helper for express-handlebars which joins elements of an array:
For example:
Should result in:
Which works great with the following helper code:
But also the following:
Should result in:
Now, for this scenario to be possible, there must be a way to render the inner template of the block helper in the helper code. This must be possible because the built-in helpers provide the same functionality.
See the following example from the handlebarsjs documentation:
The element which makes the scenario work is the options.fn fucntion, rendering the inner template based on the context. This function is missing when creating a helper for handlebars-express.
The code below results in an error because options.fn is undefined.