Use art-template in express

  1. installation

    npm install --save art-template
    npm install --save express-art-template
    
  2. Configuration

    app.engine('html',require('express-art-template'))
    

    Configure the use of the art-template template engine

    The first parameter indicates that when rendering files ending in .html, use the art-template template engine

    express-art-template is specifically used to integrate art-template into Express in Express. Although there is no need to record art-template here, it must be installed. Reason: express-art-template depends on art-template.

  3. use

    res.render('html模板名',{
          
          模板数据})
    

    Express provides a method render for the response object, which is not available by default unless the template engine is configured.

    The first parameter cannot write the path, the default will go to the views directory in the project to find the template file, which is the Express convention: the developer puts all view files in the views directory

  4. Modify the default access views directory

    app.set('views',render函数的默认访问路径);
    

Guess you like

Origin blog.csdn.net/chen__cheng/article/details/114677297