Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to write IF conditions inside Lodash templates (_.template)?

Something like:

<div>
    <%- if (condition) { %>
        <div>This text will be shown if `condition` is true</div>
    <%- } %>
</div>

The above example is not working so i'm asking if there is any way to use IF conditions inside the template string, I know that Underscore support it out of the box.

like image 406
udidu Avatar asked Dec 20 '22 02:12

udidu


1 Answers

Use this:

<% if (condition) { %>...<% } %>

(in other words: remove the hyphen)

like image 144
robertklep Avatar answered Dec 24 '22 01:12

robertklep