Kiwi is a cool JavaScript template engine lovingly built from the ground up for Node.js with performance, extensibility, modularity and security in mind. It is compatible with most of jQuery Template syntax, and adds lots of features to it. This means Kiwi is:

Fast. Insanely fast.

Completely asynchronous. You have the absolute guarantee that not a single blocking call will be done after Kiwi has been initialized.

Easily extensible. Three short lines of code are enough to create a new tag.

Used for conditional insertion of content. Renders the content between the opening and closing template tags only if the specified data item field, JavaScript function or expression does not evaluate to false (or to zero, null, type "", or the empty string).

{{else}} can be used in association with the {{if}} tag to provide alternative content based on the values of one or more expressions. The {{else}} tag can be used without a parameter, as in {{if a}}...{{else}}...{{/if}}, or with a parameter, as in {{if a}}...{{else b}}...{{/if}}.

The block of template markup between the opening and closing tags {{each}} and {{/each}} is rendered once for each data item in the data array. Within this block the {{each}} template tag exposes the current index and value as additional template variables $index and $value. These default variable names can be changed by passing in index and value parameters to the {{each}} template tag, as in the following example:

When using block tag with {{extend}}, it can be useful to append or prepend block markup to parent template block instead of replacing it. You can use the append and prepend directives to command this behavior.

Did we say that Kiwi was extensible with no more than 3 lines of code? Well, we didn't lie. For example, say you want to create a new tag {{cap}} which will capitalize its argument. Here is the only thing you'd need to do:

kiwi.tools.createSimpleTag('cap',function(context, name){

return name.toUpperCase();

});

You can then use your new tag as any other:

// Template

<div>{{cap "kiwi"}}</div>

// Code

new Template(tpl).render({}, callback);

// Result

<div>KIWI</div>

For better security, just like with the ${} tag, all output of custom tags defined that way is escaped by default. If you want your tag to input raw HTML in your document, you can mark the output as safe. For example, let's say you want to create a {{css}} tag which will render a <link> tag in your document:

Use strict mode
You can disable strict mode in order to make Kiwi comply with jQuery template / jqTpl behaviour. However, this will result in using a bunch of try…catch blocks in the compiled templates, which will definitely lower Kiwi's performance.
Strict mode is enabled by default.

Avoid using tmpl
In order to avoid memory leaks when using heavily dynamic templates in tmpl, this tag uses CappedCache by default, isolated from the main cache. As a result, if your nested templates are heavily dynamic, a new complete compiler stack is likely to be started each time a tmpl tag is met.
You may choose to use a standard cache instead, but be aware that this could easily lead to huge memory leaks if your nested templates are heavily dynamic.
It is included for compatibility with jQuery templates / jqTpl, but you should probably not use it at all.

Consider disabling eachLoopCounters
Kiwi adds counters to each loop, which allows you, for example, to access the current iteration count with $each.counter. If you don't need this functionality, disabling it will slightly increase Kiwi's performance when using each loops.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.