简体   繁体   English

节点的模板引擎不是玉

[英]Templating Engine for Node that's NOT Jade

Jade is indeed very neat, but I personally dislike the syntax and look of it. Jade确实非常整洁,但我个人不喜欢它的语法和外观。 Yeah, being able to write just : 是的,只能写:

body
  h1 Hello
  p This is 
    b bold

Thats cool and all, but I prefer the look and feel of HTML/XML still. 这很酷,但我更喜欢HTML / XML的外观和感觉。 It was made to be human and machine readable and overall I think it's easier to glance at and understand. 它被认为是人类和机器可读的整体,我认为它更容易一目了然和理解。

Are there any templating engines that work more like: 是否有任何模板引擎更像是:

<body>
  <h1>{title}</h1>
  <p>{content}</p>
</body>

Using the same Jade like concept of: 使用相同的Jade概念:

res.render('index', {
  title:pageTitle,
  content:pageContent
});

Take a look at EJS . 看看EJS Allows you to use regular HTML and embed Javascript code. 允许您使用常规HTML并嵌入Javascript代码。

For example: 例如:

<div>
<% if (foo) { %>
foo
<% }else { %>
bar
<% } %>
</div>

Also, what you're looking for is an "Express-compatible" templating engine, and EJS is Express-compatible. 此外,您正在寻找的是“Express兼容”模板引擎,EJS与Express兼容。 It's made by one of the main guys behind Express. 它是由Express背后的主要人物之一制作的。

You can use straight HTML in Jade, give this a try: 您可以在Jade中使用直接HTML,尝试一下:

<body>
  <h1>#{title}</h1>
  <p>#{content}</p>
</body>

Something that specifically looks like that would probably be Mustache for Node.js. 具体看起来像是Node.js的Mustache Check the demo . 检查演示

If you're already using underscore.js 如果你已经使用了underscore.js

var compiled = _.template("hello: <%= name %>");
compiled({name : 'moe'});
=> "hello: moe"

Consider jQuery templates . 考虑jQuery模板 You can provide your data in JSON and apply it to a template. 您可以使用JSON提供数据并将其应用于模板。

Templates can be only a matter of taste. 模板只是品味问题。 I don't like Jade either and favouring HTML is a better option. 我也不喜欢Jade,喜欢HTML是一个更好的选择。 Most of times, webdesign layouts cannot be easily converted to those templates. 大多数情况下,网页设计布局无法轻松转换为这些模板。

the sample provided moustache: 样品提供小胡子:

<h1>{{header}}</h1>
{{#bug}}
{{/bug}}

{{#items}}
  {{#first}}
    <li><strong>{{name}}</strong></li>
  {{/first}}
  {{#link}}
    <li><a href="{{url}}">{{name}}</a></li>
  {{/link}}
{{/items}}

{{#empty}}
  <p>The list is empty.</p>
{{/empty}}

It can be mixed with Angular.js syntax... could be a problem for people using it. 它可以与Angular.js语法混合......对于使用它的人来说可能是一个问题。

I recommend a new template engine: Saker, it enables fluid coding workflow, unlike most template syntaxes, you do not need to interrupt your coding to explicitly denote server blocks within your HTML. 我推荐一个新的模板引擎:Saker,它支持流体编码工作流程,与大多数模板语法不同,您不需要中断编码来明确表示HTML中的服务器块。
Github: https://github.com/eshengsky/saker Github: https//github.com/eshengsky/saker

The code looks like: 代码如下:

<body>
    <h1>@title</h1>
    <p>@content</p>
</body>

I personally use Nunjucks with all of my Node JS projects for a few years now and still loving it. 我个人将Nunjucks与我的所有Node JS项目一起使用了几年,并且仍然喜欢它。 I switched from Swig because Swig was lacking in some of extensibility when a project became more complex. 我从Swig切换,因为当项目变得更复杂时,Swig缺乏一些可扩展性。

I, too, am not a fan of Jade / Pug. 我也不是Jade / Pug的粉丝。 I prefer normal HTML syntax and inject some custom templating schemes. 我更喜欢普通的HTML语法并注入一些自定义模板方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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