Tutorial by Examples

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...
You can choose to prepend an if or else operator with a dash, but it is not necessary. You will need to wrap the statement in parentheses, though (if you omit a dash, you do not need parentheses.) - var showLogin = false; - if (showLogin === true) .welcome Welcome back to our website! - else...
You can chain any number of else if statements to an existing if statement, to evaluate a sequence of statements. index.pug - var page = 60; if page => 52 h1 Lots of numbers! else if page > 26 && page < 52 h1 A few numbers else h1 Not a lot of numbers index.pu...
unless is the inverse operation of if in Pug. It is analogous to if !(statement). index.pug - var likesCookies = true; unless likesCookies === true h2 You don't like cookies :( else h2 You like cookies! index.pug output <h1>You like cookies!</h1> Note: else unless st...

Page 1 of 1