Developing template engines for Express
Use the app.engine(ext, callback)
method to create your own template engine. ext
refers to the file extension, and callback
is the template engine function, which accepts the following items as parameters: the location of the file, the options object, and the callback function.
The following code is an example of implementing a very simple template engine for rendering .ntl
files.
Your app will now be able to render .ntl
files. Create a file named index.ntl
in the views
directory with the following content.
Then, create the following route in your app.
When you make a request to the home page, index.ntl
will be rendered as HTML.