With tags, you can do this in a gsp:
<g:if test="${someBean?.aCondition}">
<div class="aSection">
...
</div>
</g:if>
What I really want to do is add a second 'class' that either contains the 'display:none' or 'display:block' attributes based the value of '${someBean?.aCondition}'.
The final html would like this:
<div class="aSection hiddenItem">
...
</div>
(the div would have 'shownItem' for its class if ${someBean?.aCondition} is true)
The corresponding css:
.shownItem
{
display: block;
}
.hiddenItem
{
display: none;
}
What's a good way to achieve this?
Easy enough:
<div class="aSection ${someBean?.aCondition ? 'shownItem':'hiddenItem'}">
...
</div>
You can use ${} blocks inside html attributes, no problem, just be sure not to use any double-quotes in your expression block, as that confuses things.
Or if you don't want the attribute displayed at all on some (say for an autofocus tag) condition:
<input name="email" type="text" class="input-small" placeholder="Email" ${!flash.email ? 'autofocus="autofocus"':''} value="${flash.email}">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With