在Express而不是Jade中使用HTML [英] Using HTML in Express instead of Jade

查看:107
本文介绍了在Express而不是Jade中使用HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Node.JS使用Express时如何摆脱翡翠?我想要使​​用普通的html。在其他文章中,我看到人们推荐了app.register(),现在已经在最新版本中弃用了。

How to I get rid of Jade while using Express with Node.JS? I want to just use plain html. In other articles I have seen that people recommended app.register() which is now deprecated in the latest version.

推荐答案

这样做:


  1. 安装ejs:

  1. Install ejs:

npm install ejs


  • 在app.js中设置你的模板引擎作为ejs

  • Set your template engine in app.js as ejs

    // app.js
    app.engine('html', require('ejs').renderFile);
    app.set('view engine', 'html');
    


  • 现在在路由文件中可以分配模板变量

  • Now in your route file you can assign template variables

    // ./routes/index.js
    exports.index = function(req, res){
    res.render('index', { title: 'ejs' });};
    


  • 然后,您可以在/ views目录中创建html视图。

  • Then you can create your html view in /views directory.

    这篇关于在Express而不是Jade中使用HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆