Skip to content

Commit b09c2af

Browse files
hbs rendering
Signed-off-by: Arnav Gupta <[email protected]>
1 parent 4166d15 commit b09c2af

File tree

4 files changed

+113
-10
lines changed

4 files changed

+113
-10
lines changed

Lecture15/hbs-rendering/package-lock.json

+78
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lecture15/hbs-rendering/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"author": "",
1010
"license": "ISC",
1111
"dependencies": {
12-
"express": "^4.17.1"
12+
"express": "^4.17.1",
13+
"hbs": "^4.0.6"
1314
}
1415
}

Lecture15/hbs-rendering/server.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ const express = require('express')
22

33
const app = express()
44

5+
app.set('view engine', 'hbs')
6+
57
let viewcount = 0
8+
let fruits = ['Apple', 'Mango']
9+
let x = {a: 10, b: 20}
610

711
app.get('/', (req, res) => {
8-
res.send(`
9-
<html>
10-
<body>
11-
<h1>Hello</h1>
12-
<p>This is a para</p>
13-
<p>This has been viewed ${++viewcount} times</p>
14-
</body>
15-
</html>
16-
`)
12+
++viewcount
13+
res.render('home', {
14+
fruits,
15+
viewcount,
16+
x
17+
})
1718
})
1819

1920

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
<h1>Hello</h1>
11+
<p>This is a para</p>
12+
<p>This has been viewed {{viewcount}} times</p>
13+
<h2>This is a list of fruits</h2>
14+
{{fruits}}
15+
<br>
16+
{{x}} {{x.a}} {{x.b}}
17+
<ul>
18+
{{#each fruits as |f|}}
19+
<li> {{f}} </li>
20+
{{/each}}
21+
</ul>
22+
</body>
23+
</html>

0 commit comments

Comments
 (0)