ejs
ejs copied to clipboard
Print to buffer within code
I would like to conditionally print something in my template, eg:
<% if (condition) print(formatter.formatCost(cost)) %>
Currently the best way to achieve this appears to be:
<% if (condition) { %><%= print(formatter.formatCost(cost) %><% } %>
As you can see, it's convenient to have something like underscore's print().
i guess so, kinda defeats the purpose of a template IMO but sure why not it would be simple to add
Personally I'd prefer to just write that as:
<%= condition ? formatter.formatCost(cost) : '' %>
It's simple and uses things built into JavaScript, so if you're experienced with JavaScript, and you've got the hang of the <%
means it starts a block of JS and %>
closes a block of JS, you'll know what it means. print seems like a lot of magic to me. It'll aid write ability, but I think hurts readability.
@ForbesLindesay +1