javascript template engine

JavaScript HTML Template Engine

Try Semtex – the new HTML5, CSS3 and JavaScript UI framework!

Here’s a quick, dirty, reliable and library-independent client-side HTML template engine with support for prefetched templates (in a JavaScript object) and a few handy and extensible methods for compiling, adding and removing templates. Please, check the documentation in the source code and the examples at the bottom of this page for usage and more insight.

Supported Browsers

  • Mozilla Firefox
  • Google Chrome
  • Apple Safari
  • Opera
  • Internet Explorer 6-10

Please, follow @wemakesitesnet or check my website for more cool stuff.

Related Posts

Pisi HTML Template Engine 1.0 is Out!

Pisi is HTML templating engine that runs entirely in the browser. It can be used to scale down the size of ajax requests to the server by allowing them to switch from markup and data responses to data-only responses (for example JSON). Once fetched on the client, the data can be parsed by Pisi and converted to HTML and rendered on the page.

The syntax of Pisi is simple and intuitive, templates are cached on the client, so they can be used later, rendering process is fast, reliable and seamless.

Features

  • Easy and intuitive API.
  • Pure HTML with server-like function tags compiling to JavaScript.
  • Two types of templates – on-page and external.
  • Templates are compiled and cached for later use.
  • Fast and seamless execution parsing and rendering.
  • Support for different data types – variables, arrays, associative arrays (json), etc.
  • Any JavaScript can be embedded directly to the template.
  • Library-independent.
  • Only 3Kb minified and gzipped

Some Example Code

Template:

<script type="text/x-pisi-template" id="al_pacino_movies">
<h4>Al Pacino Movies</h4><ul>
<% for(var i = 0; i < pacino.length; i ++) { %>
    <li><a href="http://www.imdb.com/find?q=<%= pacino[i].replace(/\s/g, '+') %>&s=tt" title="Search IMDB for <%= pacino[i] %>" target="_blank"><%= pacino[i] %></a></li>
<% } %>
</ul></script>

Data Object:

var pacino = ["Serpico", "Dog Day Afternoon", "Scent of A Woman", "Insomnia", "Carlito's Way", "Heat"]

Template Call:

_pisi.setExternal([{
    template: "al_pacino_movies",
    data: pacino,
    callback: function(html) {
        document.getElementById("movies").innerHTML = html;
    }
]}

Rendered Markup:

<h4>Al Pacino Movies</h4>
<ul>
<li><a target="_blank" title="Search IMDB for Serpico" href="http://www.imdb.com/find?q=Serpico&amp;s=tt">Serpico</a></li>
    <li><a target="_blank" title="Search IMDB for Dog Day Afternoon" href="http://www.imdb.com/find?q=Dog+Day+Afternoon&amp;s=tt">Dog Day Afternoon</a></li>
    <li><a target="_blank" title="Search IMDB for Scent of A Woman" href="http://www.imdb.com/find?q=Scent+of+A+Woman&amp;s=tt">Scent of A Woman</a></li>
    <li><a target="_blank" title="Search IMDB for Insomnia" href="http://www.imdb.com/find?q=Insomnia&amp;s=tt">Insomnia</a></li>
    <li><a target="_blank" title="Search IMDB for Carlito's Way" href="http://www.imdb.com/find?q=Carlito's+Way&amp;s=tt">Carlito's Way</a></li>
    <li><a target="_blank" title="Search IMDB for Heat" href="http://www.imdb.com/find?q=Heat&amp;s=tt">Heat</a></li>
</ul>

If the above looks and sounds cool enough, you can go to Pisi’s home page, view the demo or download it and use it in your own projects. You can also check Templatr – another cool fully client-side JSON to HTML template engine by Acid.JS Web.UI.

Templatr HTML Template Engine 2.0 Has Been Released

I am happy to announce that just a few days after the debut of Templatr, version 2.0 has been released with tons of cool stuff. If you already know what is Templatr, just skip the next paragraphs and go directly to What’s New in Version 2.0:

What is Templatr?

Templatr is fully client-side, library-independent, lightweight (4KB minified and g-zipped), easy to use, reliable and free JSON to HTML template engine.

It can be used for scaling down AJAX-heavy applications allowing them to switch from markup- to data-only responses from the server. Once fetched on the client, the data can then be parsed and turned into beautiful HTML by Templatr and inserted in the page.

What’s New in version 2.0:

  • Now a JavaScript function returning HTML or setting more nested templates can be used for content of a parent template. Users now have three options for setting of content – a string, object (static nested templates) or function (static or fully dynamic nested templates).
  • Full support for Internet Explorer 6 and 7.
  • A few bugs have been addressed and fixed (related to the support for IE6 and 7).
  • Improved rendering speed and reliability.

Need more info? Go to Templatr’s home page, check out the demo or just download it right away! It is also included in the latest version of Acid.JS Web.UI Suite. The updated documentation can be found here.

Templatr – JSON to HTML Template Engine

Templatr is free, JSON-powered, fully client-side, library-independent, fast and responsive templating engine for HTML. It’s easy to define and use templates are parsed on the client and cached for later use. Ideally it can be used for AJAX-driven applications to reduce the requests to the server, as you can just get the data for the server and parse and render it entirely on the client by Templatr.

View demo of Templatr on this page, download it here or go to its help and manual page.