Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 

templateJS - Lightweight JavaScript Template Engine

Description

See details at templateJS.

Usage

<script src="js/template-1.1.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 500 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

About

Lightweight JavaScript Template Engine

Resources

License

Releases

No releases published

Packages

No packages published