Skip to content

Instantly share code, notes, and snippets.

@dhollenbeck
Last active November 5, 2016 18:02
Show Gist options
  • Save dhollenbeck/c4cde67aee08a3db06edf34c02ddd543 to your computer and use it in GitHub Desktop.
Save dhollenbeck/c4cde67aee08a3db06edf34c02ddd543 to your computer and use it in GitHub Desktop.
Handlebars Each New Line (nl2br)
// does not support named parameters
exports.eachNewLine = function (str, options) {
var accum = '';
var data = Handlebars.createFrame(options, options.hash);
var arr = str.split(/\r?\n/);
arr.map(function(str) {
if (str) accum += options.fn(str.trim(), {data: data});
});
return accum;
};
{{#eachNewLine textareaContent}}
<p>{{this}}</p>
{{/eachNewLine}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment