Search code examples
node.jsnpmyeomanlodashyeoman-generator

Lodash forEach function won't line break yeoman generator integration


in my yeoman generator's index.js file I have this code snippet

this.fs.copyTpl(
    this.templatePath('/index2.html'),
    this.destinationPath('app/index2.html'), {
        title: [this.templatedata.test1, this.applicationName],
        h1: this.applicationName
    }
);

I am trying to run this lodash forEach statement in my html file and it won't line break no matter what I try.

<% _.forEach(title, function(title) { %><li><%- title %></li>\n<% }); %>

The result is:

<li>Star Wars!</li>\n<li>Foundation5Application</li>\n

What I expect is

<li>Star Wars!</li>
<li>Foundation5Application</li>

Is there anything I can do to correct this forEach statement?


Solution

  • Use an actual line break:

    <% _.forEach(title, function(title) { %><li><%- title %></li> <% }); %>