-1

Is it possible to use compound if statements in an ejs template:

<% if(this.thing == 'winner' || that.thing == 'winner') { %>

I know you can use if statements in ejs. I am specifically looking for an example of compound if statements which cannot be used in all js templating schemes.

jk.
  • 14,365
  • 4
  • 43
  • 58

2 Answers2

1

Yes, ejs supports compound statements:

<%
    var fruits = ["Apple", "Pear", "Orange", "Lemon"];
%>

These fruits are amazing:
<% for(var i = 0; i < fruits.length; ++i) {%>
    <% if (fruits[i] == 'Apple' || fruits[i] == 'Lemon') {%>
        - <%=fruits[i]%>s
   <% }%>
<% } %>

Output:

These fruits are amazing:

        - Apples

        - Lemons

Thank you @JakeHolzinger

jk.
  • 14,365
  • 4
  • 43
  • 58
1

Of course yes -

<% x = 5 %>

<% if(x === 4 || x === 5) { console.log('foo')}%>
Charlie
  • 22,886
  • 11
  • 59
  • 90