pugjs能够使用三元文本? [英] pugjs able to use ternary for text?

查看:197
本文介绍了pugjs能够使用三元文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我们可以对attr使用三进制,但是我想知道我们是否可以使用纯文本?

I know we are able to use ternary for attr but I am wondering if we can do it with plain text?

假设我有类似的东西

let's say I have something like this

        button.btn.btn-round.btn-info
            |
            if image
                | Change Image
            else
                | Add Image

如果,该按钮将具有更改图像或添加图像的文本image 变量存在

是否可以使用三元?
预先感谢您的任何帮助和建议

Is this possible to use ternary? Thanks in advance for any help and suggestions

推荐答案

是的,绝对有可能。只需在元素定义的末尾使用等号即可使pug评估表达式的内容,然后使用三元运算符吐出一个字符串:

Yes, it's absolutely possible. Just use the equals sign at the end of the element definition to get pug to evaluate what follows as an expression, then use the ternary operator to spit out a string:

button.btn.btn-round.btn-info= image ? "Change Image" : "Add Image"

您可以对属性执行相同的操作:

You can do the same thing for an attribute:

button(class= image ? "green" : "red")

这篇关于pugjs能够使用三元文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆