Reputation: 1
I have a file in app.js which is being passed to handlebars for displaying the output.
The data in the file is of the format abc,Siva,Naga,def, etc.., that is every name is separated by comma(,).But,I want the data to be printed on each line separately i.e
abc
Siva
Naga
Def
I tried using various approaches like using the helpers in handle bars ,
syntax but none of them works.Reason might be handlebars treat all the data as a single object rather than array of objects.
Is there any way to fix this issue.
Upvotes: 0
Views: 1496
Reputation: 31789
This seems to work fine. Here is a working demo.
Here is the relevant code
var data = {
line: 'abc,Siva,Naga,def'
};
Handlebars.registerHelper('lineBreak', function(line, delim) {
return new Handlebars.SafeString(line.split(delim).join('<br/>'));
});
{{lineBreak line ','}}
Upvotes: 2