1. Template engine

  • In order to make the Art-template template engine can better cooperate with the Express framework, the template engine officially packaged express-Art-Template on the basis of the original Art-template template engine.
  • usenpm install art-template express-art-templateCommand to install.
// Use express-art-template when rendering templates with the art suffix
app.engine('art'.require('express-art-template'));
// Set the directory for storing the template
app.set('views', path.join(__dirname, 'views'));
// Do not write suffixes when rendering templates
app.set('view engine'.'art');
app.get('/'.(req, res) = > {
    // Render the template
    res.render('index');
});
Copy the code

2. The app. Locals object

Set variables to the app.locals object, which is available in all templates.

app.locals.users = [{
    name: 'Joe'.age: 20}, {name: 'bill'.age: 20
}]
Copy the code