ak-template
Micro-template engine.
Using John Resig's micro-template specs.
API
template(str)
description
Returns compiled template.
N.B: templates are cached.
arguments
str
String
String representing the template.
Using John Resig's micro-template format.
return
function (locals) {}
You can pass an Object
as a parameter, it will be accessible within the template through the variable locals
.
See example for more details.
template.globals
Object
Define globals: keys are defaulted with locals.
Think of it more as global defaults. Useful for sharing helper functions.
See example for more details.
template.escape(str)
Escape function, replaces <
, >
, &
, "
, '
by their equivalent HTML entity.
Can be overridden.
Example
var template = ;templateglobalstitle = 'JavaScript FTW!';templateglobals { return str + '';}; // replace // -> [Function]; // -> <h1>JavaScript FTW!</h1>'title': 'JavaScript is awesome!'; // -> <h1>JavaScript is awesome!</h1>'title': 'JavaScript is awesome!'; // -> <h1>JAVASCRIPT IS AWESOME!</h1> // using plain JS'foo': true; // -> <h1>Foo</h1>; // -> <h2>Bar</h2> // escape'word': '<script>do_evil()</script>'; // -> <script>do_evil()</script>'word': '<script>do_evil()</script>'; // -> <script>do_evil()</script> template { return str;}; 'word': '<script>do_evil()</script>'; // -> <SCRIPT>DO_EVIL()</SCRIPT>'word': '<script>do_evil()</script>'; // -> <script>do_evil()</script>
locals
and not using with
?
Why with
is evil.