Warning: Attempt to read property "ID" on bool in /www/wwwroot/129.28.78.18/wp-content/themes/storeys-pro/wbc/components/og_schema/wb_og_schema.php on line 471

Warning: Attempt to read property "display_name" on bool in /www/wwwroot/129.28.78.18/wp-content/themes/storeys-pro/wbc/components/og_schema/wb_og_schema.php on line 480

Warning: Attempt to read property "display_name" on bool in /www/wwwroot/129.28.78.18/wp-content/themes/storeys-pro/wbc/components/og_schema/wb_og_schema.php on line 487

Warning: Attempt to read property "description" on bool in /www/wwwroot/129.28.78.18/wp-content/themes/storeys-pro/wbc/components/og_schema/wb_og_schema.php on line 489

Warning: Attempt to read property "ID" on bool in /www/wwwroot/129.28.78.18/wp-content/themes/storeys-pro/wbc/components/og_schema/wb_og_schema.php on line 493

express使用ejs模板引擎渲染html文件

在使用express过程中,按照官网教程,利用express生成器很容易初始化express项目模板。

那么初始化项目之后应该如何使用ejs作为模板引擎呢?如下

// 注释掉默认生成配置
// view engine setup
// app.set('views', path.join(__dirname, 'views'));
// app.set('view engine', 'jade');
app.set('views',path.join(__dirname , 'views') );// 设置静态文件目录
//app.engine('.html', require('ejs').__express);
app.set('view engine', 'ejs'); // 设置模板引擎

又如何使用ejs渲染html文件呢?

// view engine setup
// app.set('views', path.join(__dirname, 'views'));
// app.set('view engine', 'jade');

app.set('views',path.join(__dirname , 'views') );// 设置静态文件目录
app.engine('.html', require('ejs').__express); //设置ejs渲染html
app.set('view engine', 'html');//设置html为模板引擎 注意这里是html
复制代码
  按照上面设置之后,如果不设置渲染html文件,默认服务会渲染静态目录下.ejs的文件,

如果设置渲染html文件,那么会默认渲染html后缀的文件。

评论留言