简体   繁体   English

在Express中而不是Jade中使用HTML视图

[英]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.

相关问题 Express res.redirect()返回HTML而不是重定向 - Express res.redirect() returning HTML rather than redirecting 使用Angular,Express和Jade刷新特定页面(使用html5mode) - Refresh specific page with Angular, Express and Jade (using html5mode) Node.js with Express:在Jade视图中使用脚本标签导入客户端javascript? - Node.js with Express: Importing client-side javascript using script tags in Jade views? 使用Jade在Express中更改视图 - Changing view in express using Jade 我可以将Jade配置为生成可读的良好缩进的HTML代码而不是单行流吗? - Can I configure Jade to generate readable well-indentated HTML code rather than single-line stream? 如何知道传入请求是否在express.js(而不是CSS,JS等)中要求HTML - How to know if incoming requests are asking for HTML in express.js (rather than CSS, JS, etc) Node/Express:数据库打印在屏幕上而不是 index.html - Node/Express: Database being printed on screen rather than index.html 如何使用jade&express将cdnjs css或外部css应用于nodemailer html模板 - How to apply cdnjs css or external css to nodemailer html template using jade & express 使用按钮滚动而不是滚动条css,html,javascript - Scroll using buttons rather than scroll bar css,html,javascript 如何<a>使用 JS</a>创建 Bulma 按钮元素而不是 HTML - How to create Bulma button element rather than HTML <a>, using JS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM