express - Controlling whitespace in EJS -
i have conditinal check if users not signed in class added td element. ejs looks this:
<td class="<%_ if (!currentuser) { _%> notsigned" <%_ } _%>"> rendered html:
<td class=" notsigned" "> monitor database <div class="ui accordion"> there leading whiespace on class , bracket closes on next line. i'm new ejs, what's best way control whitespace?
my ejs experience pretty limited did have 1 idea thought interesting enough share.
if add functions application locals accessible within template:
app.locals.$if = function(condition, output) { return condition ? output : ''; }; app.locals.$unless = function(condition, output) { return condition ? '' : output; }; the names $if , $unless arbitrary they're enough demonstrate idea.
you write in view:
<td class="<%= $unless(currentuser, 'notsigned') %>"> i don't know whether find easier read alternatives you've mentioned think reads quite well.
Comments
Post a Comment