Skip to content

Instantly share code, notes, and snippets.

@theycallmeswift
Created October 13, 2013 00:44
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 theycallmeswift/6956655 to your computer and use it in GitHub Desktop.
Save theycallmeswift/6956655 to your computer and use it in GitHub Desktop.
Templates with Handlebars - http://handlebarsjs.com/
<html>
<head>
<title>Foo</title>
</head>
<body>
<ul class="slider">
</ul>
<script src="js/jquery-2.0.3.min.js"></script>
<script src="js/handlebars.js"></script>
<script id="entry-template" type="text/x-handlebars-template">
<li id="{{ id }}">
<div class="poll">
<h1>{{ question }}</h1>
<a href="#yes">Yes</a>
<a href="#no">No</a>
<div class="container"></div>
</div>
</li>
</script>
<script>
function generateQuestion(id, question) {
var source = $("#entry-template").html();
var template = Handlebars.compile(source);
var context = { id: id, question: question }
var html = template(context);
$(".slider").append(html);
$("#" + id + " .container").highcharts();
}
generateQuestion(1, "What is your name?");
generateQuestion(2, "SOme other question?");
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment