Skip to content

Instantly share code, notes, and snippets.

@ronnieoverby
Created April 5, 2012 14:38
Show Gist options
  • Save ronnieoverby/2311533 to your computer and use it in GitHub Desktop.
Save ronnieoverby/2311533 to your computer and use it in GitHub Desktop.
Handlebars Experiment
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Handlebars Test</title>
<style type="text/css">
body
{
font-family: Calibri;
}
.entry
{
border: 1px dashed steelblue;
padding: 1ex;
margin:1ex;
background: skyblue;
}
</style>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://github.com/downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js"></script>
<script type="text/x-handlebars-template" id="entry-template">
{{#each items}}
{{#unless isDisgusting}}
<div class="entry">
<h2>{{title}}</h2>
<div class="body">
{{body}}
</div>
</div>
{{/unless}}
{{/each}}
</script>
<script type="text/javascript">
$(function () {
var source = $('#entry-template').html();
var template = Handlebars.compile(source);
var context = {
items:
[
{
title: "Goat Cheese for the Masses",
body: "I 'member looong time ago... goats. E'rewhere. Long liv'em. Makuh guud cheese, Ey says!"
},
{
title: "A Day on Tatooine",
body: "Mos Eisley Spaceport... you shall never find a more wretched hive of scum and villany. We must be cautious."
},
{
title: "XXX",
body: "Gasp! This is extremely innapropriate!",
isDisgusting: true
}
]
};
$('body').append(template(context));
});
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment