css - 如何在 web2py 中有条件地在 View 中添加 css 类?

标签 css web2py

在 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/

相关文章:

javascript - 将鼠标悬停在另一个元素下方的元素上

Sass源码中的PHP代码

html - 使 flexbox 中的元素占据所有垂直和水平空间

jquery - 禁用或更改 web2py 模板中的 {{}} 分隔符?

python - 将 HTML 表单输入发送到 python 脚本

python - 在 Python 中, 'x or False' 和 'False and x 有什么意义?

python - 在Python中将XML元素转换为字符串,然后将字符串转换为XML文件

javascript - 如何在 Safari 上修复 3D 变换图像上的剪辑文本?

python - 需要帮助理解模块导入错误

html - 如何制作一组样式以指向特定元素内的类