M.Dagiya
M.Dagiya

Reputation: 203

jade if statement is not working

I have the following non-functional code

div(class = "col-xs-8 inner")
    |   <label style="font-size:20px;"><%- meter_id %></label><br>
    if (type === "1")
    |   Electricity
    if (type === "0")
    |   Water

I am passing type as 1 and I still see both Electricity and Water in the output. I am not sure where I am wrong.

Upvotes: 0

Views: 342

Answers (1)

gandreadis
gandreadis

Reputation: 3242

You're missing a level of indentation after the two if-statements:

div(class = "col-xs-8 inner")
    |   <label style="font-size:20px;"><%- meter_id %></label><br>
    if (type === "1")
        |   Electricity
    if (type === "0")
        |   Water

This is because Pug only associates indented code with such blocks. That is, after if-statements, it expects code belonging in its branch to be indented.

Upvotes: 1

Related Questions