Everything you need to know about underscore template is here .
(您需要了解的关于下划线模板的所有内容都在这里 。)
Only 3 things to keep in mind:(只需记住3件事:)
-
<% %>
- to execute some code(<% %>
- 执行一些代码)
-
<%= %>
- to print some value in template(<%= %>
- 在模板中打印一些值)
-
<%- %>
- to print some values HTML escaped(<%- %>
- 打印一些HTML转义的值)
That's all about it.
(这就是它的全部。)
Simple example:
(简单的例子:)
var tpl = _.template("<h1>Some text: <%= foo %></h1>");
then tpl({foo: "blahblah"})
would be rendered to the string <h1>Some text: blahblah</h1>
(那么tpl({foo: "blahblah"})
将呈现给字符串<h1>Some text: blahblah</h1>
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…