by Before Semicolon

Route Pages

You may want to reuse the same page template for different routes. For example, all document pages you read under the /documentation path of this website uses the same template but displays different content depending on the routes and data passed to it.

Because each HTML file can only correspond to a single route path, you need to setup a dynamic express route to serve the template you want.

const {engine} = require('@beforesemicolon/html-plus');

const app = express();

engine(app, path.resolve(__dirname, './pages'));

app.get('/documentation/:doc?', (req, res) => {
	res.render('documentation', {doc: req.params.doc})

When you call the render method in the express response object, you don't need the initial forward-slash or to indicate the file extension. Every name of file you specify is known to be under the pages directory path you provided.

This is also a nice way to pass specific data per route as you will learn more about when you explore how data works with templates.

Deep nested template files

You can refer to deeply nested templates using the forward-slash to indicate nested template file.

app.get('/projects/:projectName', (req, res) => {
		{projectName: req.params.projectName}