Title: HandlebarsJS - JSON with special characters
Tags: json;backbone.js;handlebars.js
Question: I have a JSON-file which contains special characters and I want to display the JSON with HandlebarsJS but I cant get it to work:
the JSON structure is this:
"feed" : {
"entry" : {
"title": {
"$t" : "THIS TITLE I WANT"
}
}
I use BackboneJS, so inside my Collection I do:
parse: function(data) {
return data.feed.entry
So I tried to do
{{#each this}}
<p&gt;{{title.$t}}</p&gt;
{{/each}}
But it doesnt work!?!?!
Can someone tell me what is wrong?
Comment: What do you pass to handlebars?

Here is the accepted answer: You're almost there but Handlebars handles loops over properties differently.
Basically what's happening is that there's an implicit conversion of this in an each loop when dealing with objects.
{{#each this}}
//Here we think that **this** refers to an entry, but's it's not.
//Cue implicit context switch to point **this** to the title object.
//"unpack" it, and use the keys you're after.
<p&gt;{{$t}}</p&gt; //voilà, we get the value.
{{/each}}
A very simple example is this (JsBin here):
<script id="cool" type="text/x-handlebars-template"&gt;
{{#each this}}
<p&gt;{{socool}}</p&gt;
{{/each}}
</script&gt;
var cool = {cool: {'socool': "brrr!!!" }};
var compiled = Handlebars.compile(document.getElementById("cool").innerHTML);
console.log(compiled(cool));

Here is another answer: Actually, the suggestion from the user, who now has deleted his answer was right!!
{{#each this}}
<p&gt;{{title.[$t]}}</p&gt;
{{/each}}
Makes it work! So if you read this, post your answer again and I will accept it!!
Comment for this answer: You can access it like a normal property `title.$t` too.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:06/30/14', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<json><backbone.js><handlebars.js>', 'Title': 'HandlebarsJS - JSON with special characters', 'ViewCount': 608, 'id': 24487593, 'user_AboutMe': '', 'user_AccountId': 3567439.0, 'user_DisplayName': 'SHT', 'user_Reputation': 700.0, 'user_Views': 288.0, 'user_id': 2978606.0}}