pugjs able to use ternary for text?
Asked Answered
B

1

1

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

the button will have the text either Change Image or Add image if image variable exists

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

Bagnio answered 24/9, 2018 at 22:59 Comment(0)
T
1

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")
Tagliatelle answered 25/9, 2018 at 2:45 Comment(1)
Thanks thanks a lot ~ saw your answer, I believe I was over looking at some forum then. when I show people writing = image I must have though those answers are for attributes instead :( Really thanks for the answerBagnio

© 2022 - 2024 — McMap. All rights reserved.