I need the following if statement in a JSRender template:
if (UltimoStr != "0,00" && BudgetStr != "0,00" && ReseveretStr != "0,00")
{
<div class="Posts"></div>
}
but i can't figure out the syntax.
What i have so far is:
{{if UltimoStr != "0,00"}} and {{BudgetStr != "0,00"}} and {{ReseveretStr != "0,00"}}
<div class="Posts"></div>
{{/if}}
which isn't working.
I've been looking at this site for documentation, but it doesnt seem to have multiple and operators:
.html
I need the following if statement in a JSRender template:
if (UltimoStr != "0,00" && BudgetStr != "0,00" && ReseveretStr != "0,00")
{
<div class="Posts"></div>
}
but i can't figure out the syntax.
What i have so far is:
{{if UltimoStr != "0,00"}} and {{BudgetStr != "0,00"}} and {{ReseveretStr != "0,00"}}
<div class="Posts"></div>
{{/if}}
which isn't working.
I've been looking at this site for documentation, but it doesnt seem to have multiple and operators:
https://github./BorisMoore/jsrender/blob/master/demos/scenarios/02_separators-scenario.html
Share Improve this question asked May 23, 2013 at 14:17 KenciKenci 4,88216 gold badges69 silver badges113 bronze badges 1- 1 It looks as if you misinterpreted the sample above (separators scenario) in which the {{if}} {{else}} is being used to insert the string separator "and". So the "and" is nothing to do with the logical operator &&. This is a simpler example which does use "&&" :github./BorisMoore/jsrender/blob/master/demos/step-by-step/…. The reply from JcFx below looks correct to me... – BorisMoore Commented May 24, 2013 at 22:03
1 Answer
Reset to default 4This should work:
{{if UltimoStr != "0,00" && BudgetStr != "0,00" && ReseveretStr != "0,00"}}
<div class="Posts"></div>
{{/if}}
Alternatively, you could decorate the object you are binding with a single Boolean that calculates the result of that expression.
A list of operators that work in JsRender can be found here: http://msdn.microsoft./en-us/magazine/hh975379.aspx (scroll down to the section titled Expressions).
Here's a simple test:
HTML:
<body>
<h2>Result</h2>
<div id="expect-true"></div>
<div id="expect-false"></div>
</body>
<script id="template" type="text/x-jsrender">
{{:UltimoStr}}
{{:BudgetStr }}
{{:ReseveretStr }}
{{if UltimoStr != "0,00" && BudgetStr != "0,00" && ReseveretStr != "0,00"}}
<h1>True!</h1>
{{else}}
<h1>False!</h1>
{{/if}}
</script>
//JS:
$(document).ready(function() {
var trueData = {
UltimoStr: "1,00",
BudgetStr: "1,00",
ReseveretStr: "1,00"
};
$("#expect-true").append($("#template").render(trueData));
var falseData = {
UltimoStr: "0,00",
BudgetStr: "0,00",
ReseveretStr: "0,00"
};
$("#expect-false").append($("#template").render(falseData));
});
Seems to work as expected: http://jsfiddle/FJSkh/2/