Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/andrienko/chit

A tiny JS template engine snippet
https://github.com/andrienko/chit

Last synced: 7 days ago
JSON representation

A tiny JS template engine snippet

Awesome Lists containing this project

README

        

Chit.js
===

Chit.JS is a tiny js template engine based on [a post by John Resig](http://ejohn.org/blog/javascript-micro-templating/)

It is just a snippet.

Example
---

Just add something like that to header:


<h1><%= title%></h1>
<ul>
<% for ( var i = 0; i < users.length; i++ ) { %>
<li>Hello, <a href="<%=users[i].url%>"><%=users&#91;i&#93;.name%></a>!</li>
<% } %>
</ul>

Then call something like

var data = {
users:[
{name: 'John', url:'http://[email protected]'},
{name: 'Mary', url:'http://[email protected]'}
],
title:'User list:'
};

chit.render('hello',data);

The template will then be cached and rendered. Render result will be returned/