BorisMoore / jquery-tmpl

The original official jQuery Templates plugin. This project was maintained by the jQuery team as an official jQuery plugin. It is no longer in active development, and has been superseded by JsRender.
3.23k stars 1.01k forks source link

JSON with : character cannot be used in the template #118

Open kathryn-thompson opened 13 years ago

kathryn-thompson commented 13 years ago

I have the following template:

<script id="SearchResultsTemplate" type="text/x-jquery-tmpl">
{{each Hits}}
    Page ${PAGENUMBER} - ${autn:summary} 
{{/each}}
</script>'

I can pull PAGENUMBER out of the JSON but not autn:summary (it complains about the : tag presumably)

How can i escape it? I've tried \: and \; and \3A but nothing works.

Thanks

Gordon

patridge commented 13 years ago

That may be a symptom of the fact that a colon (":") isn't valid character in a JavaScript name. I won't comment on whether the colon should be used or not, but, in this case you can work around that limitation with object array notation: ${prop[autn:summary]}. It will take a tiny bit of tweaking on your {{each}}, but here is a stripped-down sample jsFiddle.

rdworth commented 13 years ago

Thanks for taking the time to submit this issue. Just wanted to let you know this plugin is no longer being actively developed or maintained by the jQuery team. See README for more info.