A MooTools-based JavaScript script template engine
Switch branches/tags
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Moo Template Engine

The Moo Template Engine (MTE) provides the means to easily create HTML templates from JavaScript and HTML. The templates let you render DOM elements which can be inserted in to the DOM tree.

The rendered elements may be customized (data bound) by supplying rendering data (a data source) upon rendering. If the data source is observable the rendered elements will observe the data source and re-render themselves whenever the data source is modified.

How to use

This section gives a super short introduction to the library with help of a few examples (not covering all features). For more demos, documentation and information please visit http://mte.null-tech.com

A simple HTML template:

<div id="template">
	<h1 data-bind="name"></h1>
	<p>You are <span data-bind="age"></span> years old!
	<a data-bind-href="homepage" data-bind="homepage"></a>

<script type="text/javascript">
	var engine = new MTEEngine.Markup();
	var template = engine.fromElement('template');

	$('page').adopt(template.render({name: 'My Name', age: 99, homepage: 'http://www.mypage.com'}));

A HTML template which renders an array:

<ul id="template" data-list="numbers">
	<li data-bind=".">			

var engine = new MTEEngine.Markup();
var template = engine.fromElement('template');

$('page').adopt(template.render({numbers: ['One', 'Two', 'Three']));

Another template created in JS:

var engine = new MTEEngine();
var template = null;

with(engine) {
	template = 
		div('Hello ', bind('name'), br(),
			'You have the following pets: ',
			div(context('pets'), {styles: {marginLeft: '10px'}}, bind())

var data = {            
	name: 'Henrik',
	pets: ['Dog', 'Hourse', 'Super Beaver']


Using templates created with HTML in a separate file which is loaded asynchronously:

var engine = new MTEEngine.Markup();

// Loading templates from external file
engine.load('templates.html', {}, function(templates) {		

More information

For more information please visit http://mte.null-tech.com