HOW TO USE IF-ELSE CONDITIONALS IN PUG | INTERPOLATION
In index.js
--------------------------------------------------------------------------------------------------
const express = require('express');
const app = express();
app.set('view engine', 'pug');
app.set('views', './views');
app.get('/', function(req, res){
//creating object of variables
var person = {
name = "Chandan",
city = "Delhi",
tutorial = "ExpressJs"
};
res.render('example', {
data : person
});
});
app.listen(80);
-----------------------------------------------------------------------------------------------------
In example.pug
-----------------------------------------------------------------------------------------------------
doctype html
html
head If-Else Conditionals In PUG
body
if (data)
h1 Hello: #{data.name}
h2 Course Name: #{data.tutorial}
h3 City: #{data.city}
else
h1(style="color : red") JavaScript Object Is Not Set.
Thankyou Chandan sir it is really helpful to me keep posting the blog.
ReplyDelete