udidu
udidu

Reputation: 8588

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.

Upvotes: 4

Views: 2285

Answers (1)

robertklep
robertklep

Reputation: 203359

Use this:

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

(in other words: remove the hyphen)

Upvotes: 11

Related Questions