I’m trying out jsRender.
What I want to do:
JS template:
<script id="theaterTemplate" type="text/x-jquery-tmpl">
{{*
if ("{{=theaterId}}" == getCurrentTheaterId()) {
}}
<a class="active" href="#">
{{*
} else {
}}
<a href="#">
{{* } }}
{{=theaterName}}
</a>
</script>
In other JS:
function getCurrentTheaterId() {
return "523";
}
Basically, in the template, if the current theater id in iteration matches what’s returned from the js function, then set the class to active. The “{{=theaterId}}” breaks in the if condition. I guess you’re not allowed to access current json properties in the if condition.
Any ideas on how to do this?
Hopefully that makes sense. Thanks!
In their sample program they have this:
http://borismoore.github.com/jsrender/demos/step-by-step/11_allow-code.html
[Edit]
You have to ‘tell’ jsRender about the external function. Here’s a working example:
[EDIT 2] A more complicated boolean condition: