Node.js和Express:用于纯HTML代码的模板引擎 [英] Node.js & Express: template engine for plain html code

查看:120
本文介绍了Node.js和Express:用于纯HTML代码的模板引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Node.js并在MEAN环境中进行表达,我正在寻找一个简单明了的模板引擎,以满足以下要求:

Using Node.js and express in a MEAN environment, I am looking for a simple and straightforward template engine, meeting these requirements:

  • 并不指示我仅使用其自己的怪异语法,而是允许我继续使用纯/纯html和js编写网页
  • 支持条件包含
  • 与Express配合使用
  • 在服务器端(Node.js/Express)上运行
  • 快速执行怪胎;)

基本上,我只是想将我的网页切成几个模块(例如,页眉,页脚等),并根据简单的条件不时地将它们包括在内.我不想使用专有的模板语言完全(重新)重建所有网页,而是准备一些我在运行时连接的html模块(与PHP相比,我只使用include指令粘贴准备好的html代码). 我看了 http://garann.github.io/template-chooser/ https://github.com/nodejs/node-v0.x -archive/wiki/modules#templating ,但这些网站似乎已经过时,根据他们的说法,没有可用的模板引擎完全满足我的要求! 有建议吗?

Basically I just want to slice my webpage into several modules (e. g. header, footer, ...) and include those now and then based on simple conditions. I don't want to entirely (re-)rebuild all webpages using a proprietary template language but rather prepare a few html modules that I concatenate at runtime (comparable to PHP where I just use the include instruction to paste prepared html code). I had a look at http://garann.github.io/template-chooser/ and https://github.com/nodejs/node-v0.x-archive/wiki/modules#templating but the sites seem outdated and according to them, there ain't no template engine available fully meeting my requirements!? Suggestions anyone?

推荐答案

我认为ejs对于您要寻找的东西来说更自然

I think ejs is more natural for what you are looking for https://scotch.io/tutorials/use-ejs-to-template-your-node-application, but jade can work also. The example in the link uses partials, which you dont need to use if ur just rendering a single page

这篇关于Node.js和Express:用于纯HTML代码的模板引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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