Node JS

PUG Switch Case Statement Demo using Node JS and PowerShell

A friend of mine asked a very good question “How can I use switch case statement in PUG using variable from route?” which took an hour time to figure it out! See the documentation for case statement here. I have a route like shown below

As usual we are calling the PS script which returns 6 as output. For our demo I can’t take the integer and render it on web page. So, I am converting to string and calling the variable DayOfWeek in case statement like shown below

Here is the PS snippet!

CASE STATEMENT IN PUG

The point here is no need to do some additional variable assignments like here! This breaks!

 

Enjoy Pug!

Leave a Reply

Your email address will not be published. Required fields are marked *