Lightweight JavaScript Template Engine
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
TestTemplateJS-Objc
TestTemplateJS-Swift
LICENSE.txt
README.md
template-1.0.js
template-1.0.min.js
test-templateJS.html

README.md

templateJS - Lightweight JavaScript Template Engine

Description

See details at templateJS.

Usage

<script src="js/template-1.0.min.js"></script>

Add template as script:

<script type="text/template" id="test-template">
<h3><@= o.title @></h3>
<ol>
<@ for (var i = 0; i < o.features.length; i++) {
     var item = o.features[i]; @>
<li><@= item.name @> <@ if (item.desc) { out += '<i>' + item.desc + '</i>'; } @></li>
<@ } @>
</ol>
<p><b><@= o.author @></b></p>
</script>

Define data modal:

var data = { 
  title: 'templateJS: lightweight JavaScript Template Engine',
  features: [
    { name: 'Build with pure JavaScript' },
    { name: 'Lightweight and Fast', desc: 'less than 600 bytes' },
    { name: 'Simple and Ease of use' }
  ],
  author: 'zhsoft88@icloud.com'
};

Render result:

var source = document.getElementById('test-template').innerText;
var tmpl = new Template(source);
var result = tmpl.render(data);
document.getElementById("output").innerHTML = result;

Template Language Guide

<@= JavaScript_Expression @>
<@ Any_JavaScript_Codes @>
o - Use it to reference template data modal
out - Use it to reference termplate output stream