Maria Minh
Maria Minh

Reputation: 1249

Lodash call function inside template

I'm using the _.template Lodash function and wanna know how to customize data values passed to it. I just wanna make something like (see toUpperCase()):

var compiled = _.template('hello ${ user.toUpperCase() } !');
compiled({ 'user': 'fred' });

Upvotes: 0

Views: 1738

Answers (1)

Deryck
Deryck

Reputation: 7658

Format inline Javascript that has a return string like so:

hello <%= user.toUpperCase() %>

Note the = after the <%

You can also run a block of code without necessarily outputting anything (though in this example I do inside the loop for kicks)

<% 
for (var i = 0;i < 10;i++){
%>
   Hello user # <%= i %>
   Welcome.
<% } %>

Upvotes: 1

Related Questions