Pug’s first-class conditional syntax allows for optional parentheses.

If you’re coming from Pug v1, you may now omit the leading -. Otherwise, it’s identical (just regular JavaScript):

- var user = {description: 'foo bar baz'}
- var authorised = false
  if user.description
    h2.green Description
    p.description= user.description
  else if authorised
    h2.blue Description
      User has no description,
      why not add one...
    h2.red Description
    p.description User has no description
<div id="user">
  <h2 class="green">Description</h2>
  <p class="description">foo bar baz</p>

Pug also provides the conditional unless, which works like a negated if. The following are equivalent:

unless user.isAnonymous
  p You're logged in as #{user.name}
if !user.isAnonymous
  p You're logged in as #{user.name}

© Pug authors
Licensed under the MIT license.