A basic template engine to explain how to make them
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LICENSE
README.md
template.js
util.js

README.md

Template

A basic template engine, built to show how to create them.

var string = [
    "<ul>",
        "${#if responses.length}",
            "${#each responses as response}",
                "<li>${response.name}</li>",
            "${#end each}",
        "${#end if}",
        "${#if !responses.length}",
            "<li><em>No responses</em></li>",
        "${#end if}",
    "</ul>"
].join("\n");

var data = {
    responses: [
        {name: "Alpha"},
        {name: "Bravo"},
        {name: "Charlie"}
    ]
};

var myTemplate = template(string);
myTemplate.render(data);
// ->
//  <ul>
//      <li>Alpha</li>
//      <li>Bravo</li>
//      <li>Charlie</li>
//  </ul>

Full details can be found on my blog.