Created
October 13, 2013 00:44
-
-
Save theycallmeswift/6956655 to your computer and use it in GitHub Desktop.
Templates with Handlebars - http://handlebarsjs.com/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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