point out that you can use print() inside of js code inside of templates

This commit is contained in:
Michael Wolf
2011-02-08 15:58:39 -06:00
parent 226b7d9344
commit ee9df31b17

View File

@@ -1097,6 +1097,16 @@ var list = "<% _.each(people, function(name) { %> <li><%= name %&
_.template(list, {people : ['moe', 'curly', 'larry']});
=&gt; "&lt;li&gt;moe&lt;/li&gt;&lt;li&gt;curly&lt;/li&gt;&lt;li&gt;larry&lt;/li&gt;"</pre>
<p>
You can also use <tt>print</tt> from within JavaScript code. This is
sometimes more convenient than using <tt>&lt;%= ... %&gt;</tt>.
</p>
<pre>
var compiled = _.template("<% print('Hello ' + epithet); %>");
compiled({epithet: "dude"});
=&gt; "Hello dude."</pre>
<p>
If ERB-style delimiters aren't your cup of tea, you can change Underscore's
template settings to use different symbols to set off interpolated code.