简体   繁体   中英

Using HTML views in Express rather than Jade

I'm setting up a new MEAN stack project and want to use Angular for my front end. I want to use HTML files for my views so I can use Angular in them. I'm having trouble setting the Express 'view engine' to HTML. I found one solution that works here, written by Andrew Homeyer.

But with this method, I'll have to double up all my view templates? For example, index.jade-index.html, planets.jade-planets.html and so on? Is there any better way to do this? Thanks so much guys.

I understand your question but Why do you want to use "html" this meaning you don't want to compile the templates or better, you do not want a template engine. This means you will not be able to pass variables to the template. which can be ok, but then why do you want to include the source code in your server app and not just creating a separate app for your angular app?

While if you are looking for a template engine which is like HTML but having some variable parsing you can use Swig http://paularmstrong.github.io/swig/

If you want to use Swig (which are .html files)

var swig = require('swig');

app.engine('html', swig.renderFile);

app.set('view engine', 'html');

http://paularmstrong.github.io/swig/docs/#express here the full docs for express implementation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM