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
Copy file name to clipboardExpand all lines: src/content/docs/en/4x/guide/using-template-engines.mdx
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: Using template engines with Express
3
-
description: Discover how to integrate and use template engines like Pug, Handlebars, and EJS with Express.js to render dynamic HTML pages efficiently.
3
+
description: Discover how to integrate and use template engines like Pug, Handlebars-compatible engines, and EJS with Express.js to render dynamic HTML pages efficiently.
@@ -10,15 +10,15 @@ A _template engine_ enables you to use static template files in your application
10
10
variables in a template file with actual values, and transforms the template into an HTML file sent to the client.
11
11
This approach makes it easier to design an HTML page.
12
12
13
-
The [Express application generator](/starter/generator) uses [Pug](https://pugjs.org/api/getting-started.html) as its default, but it also supports [Handlebars](https://www.npmjs.com/package/handlebars), and[EJS](https://www.npmjs.com/package/ejs), among others.
13
+
The [Express application generator](/starter/generator) uses [Pug](https://pugjs.org/api/getting-started.html) as its default, but it can generate apps configured for Handlebars-compatible engines such as [hbs](https://www.npmjs.com/package/hbs),[EJS](https://www.npmjs.com/package/ejs), among others.
14
14
15
-
To render template files, set the following [application setting properties](/api/application/#appset), in the default `app.js` created by the generator:
15
+
For apps created by the generator, these settings are added to the generated `app.js`. For apps you create without the generator, set the following [application setting properties](/api/application/#appset) yourself:
16
16
17
17
-`views`, the directory where the template files are located. Eg: `app.set('views', './views')`.
18
18
This defaults to the `views` directory in the application root directory.
19
19
-`view engine`, the template engine to use. For example, to use the Pug template engine: `app.set('view engine', 'pug')`.
20
20
21
-
Then install the corresponding template engine npm package; for example to install Pug:
21
+
Then install the corresponding Express-compatible template engine npm package; for example to install Pug:
@@ -28,6 +28,7 @@ which `res.render()` calls to render the template code.
28
28
29
29
Some template engines do not follow this convention. The [@ladjs/consolidate](https://www.npmjs.com/package/@ladjs/consolidate)
30
30
library follows this convention by mapping all of the popular Node.js template engines, and therefore works seamlessly within Express.
31
+
For example, install [hbs](https://www.npmjs.com/package/hbs) or any other Express-compatible Handlebars view engine instead of the raw `handlebars` package by itself.
Copy file name to clipboardExpand all lines: src/content/docs/en/5x/guide/using-template-engines.mdx
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: Using template engines with Express
3
-
description: Discover how to integrate and use template engines like Pug, Handlebars, and EJS with Express.js to render dynamic HTML pages efficiently.
3
+
description: Discover how to integrate and use template engines like Pug, Handlebars-compatible engines, and EJS with Express.js to render dynamic HTML pages efficiently.
@@ -10,15 +10,15 @@ A _template engine_ enables you to use static template files in your application
10
10
variables in a template file with actual values, and transforms the template into an HTML file sent to the client.
11
11
This approach makes it easier to design an HTML page.
12
12
13
-
The [Express application generator](/starter/generator) uses [Pug](https://pugjs.org/api/getting-started.html) as its default, but it also supports [Handlebars](https://www.npmjs.com/package/handlebars), and[EJS](https://www.npmjs.com/package/ejs), among others.
13
+
The [Express application generator](/starter/generator) uses [Pug](https://pugjs.org/api/getting-started.html) as its default, but it can generate apps configured for Handlebars-compatible engines such as [hbs](https://www.npmjs.com/package/hbs),[EJS](https://www.npmjs.com/package/ejs), among others.
14
14
15
-
To render template files, set the following [application setting properties](/api/application/#appset), in the default `app.js` created by the generator:
15
+
For apps created by the generator, these settings are added to the generated `app.js`. For apps you create without the generator, set the following [application setting properties](/api/application/#appset) yourself:
16
16
17
17
-`views`, the directory where the template files are located. Eg: `app.set('views', './views')`.
18
18
This defaults to the `views` directory in the application root directory.
19
19
-`view engine`, the template engine to use. For example, to use the Pug template engine: `app.set('view engine', 'pug')`.
20
20
21
-
Then install the corresponding template engine npm package; for example to install Pug:
21
+
Then install the corresponding Express-compatible template engine npm package; for example to install Pug:
@@ -28,6 +28,7 @@ which `res.render()` calls to render the template code.
28
28
29
29
Some template engines do not follow this convention. The [@ladjs/consolidate](https://www.npmjs.com/package/@ladjs/consolidate)
30
30
library follows this convention by mapping all of the popular Node.js template engines, and therefore works seamlessly within Express.
31
+
For example, install [hbs](https://www.npmjs.com/package/hbs) or any other Express-compatible Handlebars view engine instead of the raw `handlebars` package by itself.
0 commit comments