在 web2py View 中,是否有一种基于条件将 css 类添加到 html 标记的简洁方法?我在想这样的伪代码:
<div class="details {{if product.inventory == 0 then 'highlight'}}">...</div>
如果 product.inventory == 0 那么 View 将生成以下 html:
<div class="details highlight">
否则:
<div class="details">
我知道我可以在 View 中使用普通的旧 if block ,但我正在寻找一种简洁的方法来执行此操作。或者有更好的方法来解决这个问题吗?
最佳答案
你快搞定了:
<div class="details{{=' highlight' if product.inventory == 0 else ''}}">
关于css - 如何在 web2py 中有条件地在 View 中添加 css 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19775323/