jseval and if statement

30 views
Skip to first unread message

nikkia

unread,
Sep 27, 2010, 5:46:42 PM9/27/10
to google-jstemplate
I'm trying to use the jseval instruction to check an attribute value
and then add a css class if that attribute value is true. Can I use
an if statement within the jseval context? I'm attempting this:

var cssClass = 'nda';
processingContext.setVariable('$cssClass', cssClass);

<div id="tpl2">
<span jsselect="title"></span>
<ul jsdisplay="items.length" id="topnav">
<li jsselect="items" jseval="if(current==false){$cssClass =
'no_nda';}">
<!--Recursive tranclusion: -->
<a href="#"
jsvalues="title:hoverMessage;href:action;target:target;class:
$cssClass"><span jscontent="title"></span></a>
<div transclude="topnav"></div>
</li>
</ul>
</div>

The above code will assign the class 'nda' to all links - not
'no_nda'. Changing the eval to this:

<li jsselect="items" jseval="alert(current);">

Shows that all items (except one) have the current attribute set to
false.

mesch

unread,
Sep 27, 2010, 6:10:00 PM9/27/10
to google-jstemplate
Use the ternary operator for conditional expressions:

<li jsselect="items">
<a href="#" jsvalues="class:current ? 'nda' : 'no_nda';"><span
jscontent="title"></span></a>
</li>
Reply all
Reply to author
Forward
0 new messages