Last active
August 23, 2016 22:49
-
-
Save pcote/febd60826dd684e71cc8072d5534d0c1 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Handlebars looping example</title> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.min.js"></script> | |
</head> | |
<body> | |
<div id="targetArea"></div> | |
<script id="listTemplate" type="text/x-handlebars-template"> | |
<ul> | |
{{#each wordList}} | |
<li>{{this}}</li> | |
{{/each}} | |
</ul> | |
</script> | |
<script> | |
$(function(){ | |
var data = { wordList: "This is my list of words".split(" ") }; | |
var templateText = $("#listTemplate").html(); | |
var template = Handlebars.compile(templateText); | |
var renderedText = template(data); | |
var renderedDom = $(renderedText); | |
$("#targetArea").append(renderedDom); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment