Skip to content

Instantly share code, notes, and snippets.

@DohMoose
Created September 13, 2010 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DohMoose/576680 to your computer and use it in GitHub Desktop.
Save DohMoose/576680 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script>
// IE doesn't have trim method
if(typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
}
}
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="/javascripts/handlebars.js"></script>
</head>
<body>
<div id="current_order"></div>
<script type="text/x-handlebars-template" name="order_items">
<h4>Your Order</h4>
<table>
{{#lines}}
<tr class="order_line" id="{{id}}">
<th>{{description}}</th>
<td>{{price}}</td>
</tr>
{{/lines}}
<tfoot>
<th>Total</th>
<td>{{total}}</td>
<tfoot>
</table>
</script>
<script>
var data = {"lines":[{"price":1200,"id":"4c8c63786f543b276800000d","description":"Margherita"},{"price":1200,"id":"4c8c648c6f543b2768000040","description":"Margherita"},{"price":950,"id":"4c8c5aa9055f486ef6000004","description":"Italian Sausage"},{"price":1600,"id":"4c8c5dd72619de3112000010","description":"Wild Mushroom"}],"total":4950}
var source = $("script[name=order_items]").html();
var template = Handlebars.compile(source);
$("#current_order").html(template(data)).show();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment