Skip to content

Instantly share code, notes, and snippets.

@silentrob
Created August 14, 2010 20:42
Show Gist options
  • Save silentrob/524697 to your computer and use it in GitHub Desktop.
Save silentrob/524697 to your computer and use it in GitHub Desktop.
var templateData = this.responseText;
var data = {
person: {
name : {
first : 'Rob',
last : 'Ellis'
},
age: 30,
location : {
city : 'Vancouver'
}
},
ul : {
item : ['one','two','three']
}
}
// The Data drives the Data Binding, and Flow
// Each Key is checked to see if a template existed by the same ID and called with the resulting data passed in
// Arrays are iterated over and called inline.
// Loads the templates from the XHR Request
x$(window).loadTemplate(templateData);
x$("#main").applyTemplate(data);
<div id="main">
<p>This is the person template</p>
<p>
<span>Rob</span>&nbsp;<span>Ellis</span>
<p>This is the Location template</p>
<p><span data="city">Vancouver</span></p>
<ul>
<li>This is an item one</li>
<li>This is an item two</li>
<li>This is an item three</li>
</ul>
</p>
</div>
<template id="person">
<p>This is the person template</p>
<p><span><%= name.first %></span>&nbsp;<span><%= name.last %></span></p>
</template>
<template id="location">
<p>This is the Location template</p>
<p><span data='city'><%= city %></span></p>
</template>
<template id="ul">
<ul></ul>
</template>
<template id="item">
<li>This is an item <%= locals %></li>
</template>
@vhs
Copy link

vhs commented Aug 15, 2010

We have HTML templates that we re-use server side (via Template::Toolkit) and client side (via Jemplate). Our build process uses jemplate to compile the slides into .js. It works great and has the very rich syntax that Template::Toolkit offers. Not limited to producing HTML either. --oops this is lukec not vhs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment