pug Conditionals If/Else Statement in Pug


Example

Conditionals in Pug can evaluate statements in a manner similar to JavaScript. You can evaluate variables created in Pug, or those passed to it by your route (res.render, pug.renderFile, etc).

index.js

var authorized = true
res.render("index", {
    authorized: authorized
});

index.pug

- var showLogin = false;
if authorized && showLogin === true
    .welcome Welcome back to our website!
else
    .login
        a(href="/login") Login

index.pug output

<div class="login"><a href="/login">Login</a></div>