是否可以在Lodash模板(_.template)中编写IF条件?

udi*_*idu 3 javascript lodash

就像是:

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

上面的例子没有用,所以我问是否有任何方法在模板字符串中使用IF条件,我知道Underscore支持开箱即用.

rob*_*lep 8

用这个:

<% if (condition) { %>...<% } %>
Run Code Online (Sandbox Code Playgroud)

(换句话说:删除连字符)