[英]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. 我正在建立一个新的MEAN堆栈项目,并想在我的前端使用Angular。 I want to use HTML files for my views so I can use Angular in them. 我想为视图使用HTML文件,以便可以在其中使用Angular。 I'm having trouble setting the Express 'view engine' to HTML. 我无法将Express“视图引擎”设置为HTML。 I found one solution that works here, written by Andrew Homeyer. 我找到了一个由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? 例如,index.jade-index.html,planets.jade-planets.html等? 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. 我理解您的问题,但是为什么要使用“ html”,这意味着您不想编译模板或更好的模板,也不想使用模板引擎。 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/ 如果您正在寻找类似于HTML的模板引擎,但是具有一些变量解析功能,则可以使用Swig http://paularmstrong.github.io/swig/
If you want to use Swig (which are .html files) 如果要使用Swig(.html文件)
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 http://paularmstrong.github.io/swig/docs/#express此处是完整实施的完整文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.