Skip to content

Instantly share code, notes, and snippets.

@ankitnetwork18
Created January 12, 2013 08:42
Show Gist options
  • Save ankitnetwork18/4516793 to your computer and use it in GitHub Desktop.
Save ankitnetwork18/4516793 to your computer and use it in GitHub Desktop.
jquery: jquery templating demo
<html>
<head>
<title>jQuery templating</title>
<script src="jquery.js"></script>
<script src="jquery-templating.js"></script>
<script>
jQuery(function($){
//create array or object of values to append in html
var movies = [
{ Name: "The red volin", ReleaseYear: "1998" },
{ Name: "Eyes wide shut", ReleaseYear: "2012" },
{ Name: "The inheritence", ReleaseYear: "1976" }
];
//trigger jquery templating on defined template
$("#movieTemplate").tmpl(movies).appendTo("#movieList");
});
</script>
</head>
<body>
<!-- define jquery template in html -->
<script id="movieTemplate" type="text/x-jquery-tmpl">
<li>
<b>${Name}</b> (${ReleaseYear})
</li>
</script>
<!-- write the jquery template data -->
<ul id="movieList"></ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment