pug Conditionals


Introduction

Pug can conditionally run code based on variables (passed from your server or based in Pug itself).

Syntax

  • if (statement)

    // Pug code
    
  • else if (statement)

    // Pug code
    
  • else

    // Pug code
    
  • unless (statement)

    // Pug code
    

Parameters

ParameterDetails
if (statement)Evaluates statement to see if it returns true or false. The code nested underneath if will run only if statement returns true.
else if (statement)Chained to an existing if or else if statement; it only runs if the previous statement evaluated to false. The code nested underneath the else if statement will run only if statement evaluates to true.
elseThe code nested underneath the else statement will run only if all previous statements returned false.
unless (statement)The negation of if (statement); the code nested underneath if will run only if statement returns false. It is the same as if (!statement).

Remarks