mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +00:00
Add varname to _.templateSettings.
* Leave out the with statement when using varname. * Rename source to compiled. * Comments, comments, comments.
This commit is contained in:
23
index.html
23
index.html
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="chrome=1">
|
||||
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
|
||||
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
|
||||
<title>Underscore.js</title>
|
||||
<style>
|
||||
body {
|
||||
@@ -1348,6 +1348,7 @@ _.result(object, 'stuff');
|
||||
object as the second parameter to <b>template</b> in order to render
|
||||
immediately instead of returning a template function.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
var compiled = _.template("hello: <%= name %>");
|
||||
compiled({name : 'moe'});
|
||||
@@ -1393,16 +1394,28 @@ var template = _.template("Hello {{ name }}!");
|
||||
template({name : "Mustache"});
|
||||
=> "Hello Mustache!"</pre>
|
||||
|
||||
<p>
|
||||
By default, <b>template</b> places the values from your data in the local scope
|
||||
via the <tt>with</tt> statement. However, you can specify a single variable name
|
||||
with the <b>varname</b> setting.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
_.templateSettings.varname = 'data';
|
||||
var template = _.template("<%= data.hasWith %>");
|
||||
template({hasWith: 'no'});
|
||||
=> "no"</pre>
|
||||
|
||||
<p>
|
||||
Precompiling your templates can be a big help when debugging errors you can't
|
||||
reproduce. This is because precompiled templates can provide line numbers and
|
||||
a stack trace, something that is not possible when compiling templates on the client.
|
||||
<b>template</b> provides the <b>source</b> property on the compiled template
|
||||
<b>template</b> provides the <b>compiled</b> property on the compiled template
|
||||
function for easy precompilation.
|
||||
</p>
|
||||
|
||||
<pre><script>
|
||||
JST.project = <%= _.template(jstText).source %>;
|
||||
JST.project = <%= _.template(jstText).compiled %>;
|
||||
</script></pre>
|
||||
|
||||
|
||||
@@ -1570,8 +1583,8 @@ _([1, 2, 3]).value();
|
||||
<b class="header">1.2.4</b> — <small><i>Jan. 4, 2012</i></small><br />
|
||||
<ul>
|
||||
<li>
|
||||
You now can (and probably should, as it's simpler)
|
||||
write <tt>_.chain(list)</tt>
|
||||
You now can (and probably should, as it's simpler)
|
||||
write <tt>_.chain(list)</tt>
|
||||
instead of <tt>_(list).chain()</tt>.
|
||||
</li>
|
||||
<li>
|
||||
|
||||
Reference in New Issue
Block a user