In the remaining part of the chapter, we are going to integrate a template engine with Express, specifically the template
function from the lodash
module (this can be applied for other template engines too).
But what do we have to do exactly? We are going to tackle the following issues:
How the template engine's rendering function gets called (what arguments are called)
What the function should return
Caching and cache invalidation
Partials and layouts
The rendering function from Express calls the template engine function with the following arguments:
The path of the template file
The locals passed to the
response.render
function when called (as the second argument)A callback function that should be called with the (
error
andcontent
) arguments
Let's make a small sample application and an empty view file and see exactly what gets logged to the console:
app.set('views', __dirname + '/views'); app.engine('html', function() { console.log(arguments); }); app...