开发者

Can this Play template code be simplified (avoid if/else tag)?

I have the following html code:

#{if title == 'Subnet' }
    <li><a href="@{SubnetController.list}" class="selected">&{'subnet'}开发者_如何学运维</a></li>
#{/if}
#{else}
    <li><a href="@{SubnetController.list}">&{'subnet'}</a></li>
#{/else}

Is it possible to do that with less code, maybe using a groovy operator I am not aware of?


<li><a href="@{SubnetController.list}" #{if title == 'Subnet'} class="selected" #{/if} >&{'subnet'}</a></li>

should do the trick.


following should also do the trick:

<li><a href="@{SubnetController.list}" #{title == 'Subnet'? 'class="selected"' : ''}>&{'subnet'}</a></li>


I usually use custom tags to encapsulate presentation logic in my templates so in your case, I'd have:

<li><appName:subnetLink title=${title} /></li>

My 2 cents.


following should also do the trick:

 <li> <a href="@{SubnetController.list}" ${title == 'Subnet'? 'class="selected"'.raw() : ''}> 
 ${'subnet'}</a></li>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜