Can I use conditional statements with EJS templates (in JMVC)?

前端 未结 7 501
误落风尘
误落风尘 2020-11-30 19:16

and if yes, what is the syntax? My goal is to prepend an \'s\' to the word \'comment\' when there is more than one. in an jQuery.ejs template in a JMVC app. The following br

7条回答
  •  悲&欢浪女
    2020-11-30 20:04

    Conditionals work if they're structured correctly, I ran into this issue and figured it out.

    For conditionals, the tag before else has to be paired with the end tag of the previous if otherwise the statements will evaluate separately and produce an error.

    ERROR!

    <% if(true){ %>
       

    foo

    <% } %> <% else{ %>

    bar

    <% } %>

    Correct

    <% if(true){ %>
       

    foo

    <% } else{ %>

    bar

    <% } %>

    hope this helped.

提交回复
热议问题