Template Engine - node Js

 admin.js

 

 Here the intresting thing is that just adding it in 1 route we can access the data in the other field. That's really intresting. Here we are not using module.exports as it has got two exports.

 

shop.js

 


 

and if we console it than we wil get the data.

The main disadvantgae is that data is shared among all user. So, it can be access by anyone

 

Templating Engine

npm i --save ejs pug express-handlebars

To use a templating engine evrweher

 

Use app.set (Although app.set has more features u can read it in express documentation
)

Although the view folders by default is already currrent directory/views but for demonstration purpose we aare still doing it.

 create shop.pug

 But we are not telling node js to render it..although we have set everything but we havnt yet told them ..so lets tell them

 Outputing dynamic content using pug

We can pass dynamic content as shown below

 and than we can driectly use it in our admin.js

Here you are seeing title is dynamic instead of static content



 

 In this you are seeing each prodduct in prods a special syntax provided by pug and also html is written as per pug

 EJS

1) 404 page


 

Working on Layout wth partials

Create folder named includes

We are sharing three common code head.ejs ,nav.ejs and endi.js

1) Head.ejs


It contains shared head code 


Add the common code to than 404 page . the location should be seeing from 404 page to the partial file and it will than get render

We are adding - so as to add script as well. It is done so as hackers can't add unitenitional files. If we don't add than it will render as text.

 

ii)end.ejs

 

 

j

 

Comments

Popular posts from this blog

Form Part 2

Event mini project by Thapa#33

De-mystifying 'this' keyword of Javascript