You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In your project folder, you should (for now) have a javascript file and a 'views' folder.
Inside the views folder, create a file called 'main.hbs'. Also, create a directory called 'layouts'.
inside the 'layouts' directory, create a file called 'steam-layout.hbs' for example.
leave the 'main.hbs' file empty.
the 'steam-layout.hbs' file should contain:
Notice that we need to include the variables {{title}} and {{message}}
now change your js-code to:
constexpress=require('express');consthandlebars=require('express-handlebars');constpath=require('path');constapp=express();app.set("view engine","hbs");app.engine("hbs",handlebars({layoutsDir: __dirname+"/views/layouts",extname: "hbs",}));app.get("/",(req,res)=>{res.render("main",{layout: "steam-layout",title: "Hey There, World!",message: "This is a fantastic example of Handlebars!",});});app.listen(3037);
I'm also new to handlebars but there are some great guides that explain the concept of views, layouts, and partials in detail.
check out: https://bit.ly/37sqYsu
I get this error:
Error: ENOENT: no such file or directory, open '..\views\layouts\main.handlebars'
Whenever I add this code:
This is from chapter 4.
The text was updated successfully, but these errors were encountered: