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

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -