You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<metaname="description" content="doT.js - the fastest and concise javascript template engine for Node.js and browsers"/>
7
-
<style>
8
-
body{background-color:#f4f4f4;color:#555;max-width:800px;padding:20px;font-size:16px;font-weight:200;margin:0 auto;font-family:Helvetica Neue,arial,verdana}h1{color:#708090;text-shadow:01px2px#fff;font-size:4em;text-align:center}.subtitle{text-align:center;margin-bottom:60px}h2{text-shadow:01px2px#fff}h2span{font-weight:200;font-size:14px}a{color:#a80000}.smaller{font-size:.8em}h4{margin:4px0;font-weight:400;font-size:20px}textarea{border:1px solid lightgrey;outline:none;font-size:14px;width:96%;height:210px;padding:10px;text-align:left}.templategroup,.datagroup,.functiongroup,.resultgroup{width:48%;margin:4px2%4px0;float:left;min-width:300px}.function,.result{background:#DDD;height:212px;padding:10px;font-size:14px;overflow-y:auto}.definegroup{display:none}.templategroup.withdefs .definegroup{display:block}.templategroup.withdefs .template{height:90px}textarea.defines{height:60px}.stripgroup{padding-top:8px;width:160px;float:left}code{font-size:14px;font-weight:bold}#sampletabs{list-style:none;margin:0;padding:0}#sampletabsli{float:left;margin:4px;padding:4px8px;background:#DDD;cursor:pointer}#sampletabsli.active{background:#fa8072;color:#FFF}@media all and (max-width:740px){.templategroup,.datagroup,.functiongroup,.resultgroup{width:100%;margin-right:0}pre{overflow-x:scroll}}</style>
4
+
<metacharset="utf-8"/>
5
+
<metahttp-equiv="Refresh" content="0;url=.." />
9
6
</head>
10
7
<body>
11
-
<ahref="http://github.com/olado"><imgstyle="position: absolute; top: 0; left: 0; border: 0;" src="https://a248.e.akamai.net/camo.github.com/5d21241b64dc708fcbb701f68f72f41e9f1fadd6/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f6c6566745f7265645f6161303030302e706e67" alt="Form me on GitHub"></a>
12
-
13
-
<h1>doT.js</h1>
14
-
<h2class="subtitle">The fastest + concise javascript template engine<br/>for Node.js and browsers.</h2>
15
-
16
-
<h2>Origins</h2>
17
-
<p>
18
-
doT.js was created in search of the fastest and concise JavaScript templating function with emphasis on performance under V8 and Node.js.
19
-
It shows great performance for both Node.js and browsers.
20
-
<br/>
21
-
<p>
22
-
During my quest I found 2 template engines that caught my attention and inspired doT.
23
-
<br/>The first one was jQote2, a jQuery plugin, it was the first engine to break the speeds by using string concatenation and avoiding 'with' statements.
24
-
<br/>The second one was underscore.js which had a nicely designed extension friendly templating function.
<h3>Compile time evaluation vs Runtime evaluation</h3>
87
-
You can improve performance further if you use compile time evaluation. It is useful in cases when the data that you want to use are not changing with each run of the template. Think of it as defines or constant variables.
88
-
<p>It is also used to statically compile partials. This comes in handy when you want to include similar header and footer on multiple pages. doT also allows to customize partial right from the template that will include it.</p> Check <ahref="https://github.com/olado/doT/blob/master/examples/advancedsnippet.txt">advanced sample</a> and <ahref="https://github.com/olado/doT/blob/master/examples/browsersample.html">one more sample</a> for hints on how to use defines and partials.
89
-
90
-
<h2>Benchmarks</h2>
91
-
<p>
92
-
Here is the <ahref="http://jsperf.com/dom-vs-innerhtml-based-templating/53">first benchmark</a> of doT in jsperf.<br/>
93
-
Here is a more <ahref="http://jsperf.com/dom-vs-innerhtml-based-templating/413">recent benchmark</a> against the new and upgraded engines that popped up lately.
94
-
<br/>
95
-
People are constantly adding new javascript template engine benchmarks.
96
-
</p>
97
-
Additional benchmarks are available in <ahref="https://github.com/olado/doT/tree/master/benchmarks">github</a>
98
-
<divclass="smaller">
99
-
<p>
100
-
To run the benchmarks for measuring execution of compiled templates:
101
-
<br/>
102
-
In the browser: navigate to benchmarks/index.html or go <ahref="http://olado.github.com/doT/bench.html">here</a>
103
-
<br/>
104
-
With node: node benchmarks/templatesBench.js
105
-
</p>
106
-
<p>
107
-
To run the benchmarks for measuring compilation speed:
108
-
<br/>In the browser: navigate to benchmarks/genspeed.html
109
-
<br/>
110
-
With node: node benchmarks/compileBench.js
111
-
</div>
112
-
113
-
<h2>Installation</h2>
114
-
<h3>For Node.js</h3>
115
-
<p>If you plan to use doT with Node.js, you can install doT with npm:
116
-
<p><code>> npm install dot</code></p>
117
-
Then use <code>require('dot')</code> in your code.
By default, the data in the template must be referenced with 'it'. To change the default variable name, modify setting 'varname'. For example, if you set 'varname' to "foo, bar" you will be able to pass 2 data instances and refer to them from the template by foo and bar.</p>
164
-
<p>
165
-
To control whitespace use 'strip' option, true - to strip, false - to preserve.
166
-
</p>
167
-
<p>
168
-
'append' is a performance optimization setting. It allows to tweak performance, depending on the javascript engine used and size of the template, it may produce better results with append set to false.
169
-
</p>
170
-
<p>
171
-
If 'selfcontained' is true, doT will produce functions that have no dependencies on doT. In general, generated functions have no dependencies on doT, with the exception for encodeHTML and it is only added if encoding is used. If 'selfcontained' is true and template needs encoding, encodeHTML function will be included in the generated template function.
<p>Call this function to compile your template into a function.</p>
176
-
<code> function(tmpl, c, def) </code>
177
-
<ul>
178
-
<li>tmpl - template text
179
-
</li><li>
180
-
c - custom compilation settings, if null, doT.templateSettings is used
181
-
</li><li>
182
-
def - data for compile time evaluation, see <ahref="https://github.com/olado/doT/blob/master/examples/advancedsnippet.txt">advanced sample</a>.</p>
183
-
</li></ul>
184
-
By default, the produced function expects one parameter - data - with the name 'it'. The names and number of parameters can be changed by changing doT.templateSettings.varname </p>
0 commit comments