I've been trying to learn to use jQuery Javascript Templates. I was following the tutorial here: http://net.tutsplus.com/tutorials/javascript-ajax/quick-tip-working-with-the-official-jquery-templating-plugin/ (which takes receives tweets from twitter).
I believe I have followed the code perfectly, I have put it here http://jqupload.herokuapp.com/tmpl
The code is here. All the scripts/stylesheets seem to be referenced correctly and the code seems to be correct according to the tutorial.
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="public/stylesheets/tmpl-style.css" />
<script src="public/javascripts/jquery-1.6.4.min.js"></script>
<script src="public/javascripts/jquery.tmpl.js"></script>
</head>
<body>
<h1> Tweets about Nettuts+ </h1>
<script id="tweets" type="text/x-jquery-tmpl">
<li>
<img src="${imgSource}" alt="${username}" />
<h2> ${username} </h2>
<p> ${tweet} </p>
{{if geo}}
<span>
${geo}
</span>
{{/if}}
</li>
</script>
<ul id="twitter"></ul>
<script>
$.ajax({
type : 'GET',
dataType : 'jsonp',
url : 'http://search.twitter.com/search.json?q=nettuts',
success : function(tweets) {
var twitter = $.map(tweets.results, function(obj, index) {
return {
username : obj.from_user,
tweet : obj.text,
imgSource : obj.profile_image_url,
geo : obj.geo
};
});
$('#tweets').tmpl(twitter).appendTo('#twitter');
}
});
</script>
</body>
</html>
Using firebug I can see that the correct information is received from Twitter, but the tweets don't actually get displayed. Can anyone please help?
You got a spelling mistake in your template - change
alt="${userName}"
to
alt="${username}"
It probably fails silently without it.
It also looks like ${attributes}
got removed somehow from your deployed app.