ejs icon indicating copy to clipboard operation
ejs copied to clipboard

Print to buffer within code

Open wachunga opened this issue 12 years ago • 3 comments

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().

wachunga avatar Jul 31 '12 21:07 wachunga

i guess so, kinda defeats the purpose of a template IMO but sure why not it would be simple to add

tj avatar Jul 31 '12 21:07 tj

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 avatar Sep 18 '12 22:09 ForbesLindesay

@ForbesLindesay +1

ArkeologeN avatar Dec 21 '13 20:12 ArkeologeN