NodeJS 模板引擎 Swig-NodeJS

码农软件 · 软件分类 · 模板引擎 · 2019-08-22 22:29:05

软件介绍

swig 是node端的一个优秀简洁的模板引擎,类似Python模板引擎Jinja,目前不仅在node端较为通用,相对于jadeejs优秀,而且在浏览器端也可以很好地运行。

特性:

  • 支持大多数主流浏览器。

  • 表达式兼容性好。

  • 面向对象的模板继承。

  • 将过滤器和转换应用到模板中的输出。

  • 可根据路劲渲染页面。

  • 支持页面复用。

  • 支持动态页面。

  • 可扩展、可定制。

使用示例:

模板代码

<h1>{{ pagename|title }}</h1>
<ul>
{% for author in authors %}
    <li{% if loop.first %} class="first"{% endif %}>{{ author }}</li>
{% endfor %}
</ul>

node.js 代码:

var swig  = require('swig');
var template = swig.compileFile('/absolute/path/to/template.html');
var output = template({
    pagename: 'awesome people',
    authors: ['Paul', 'Jim', 'Jane']
});

输出

<h1>Awesome People</h1>
<ul>
    <li class="first">Paul</li>
    <li>Jim</li>
    <li>Jane</li>
</ul>

本文地址:https://www.codercto.com/soft/d/12958.html

The Art and Science of Java

The Art and Science of Java

Eric Roberts / Addison-Wesley / 2007-3-1 / USD 121.60

In The Art and Science of Java, Stanford professor and well-known leader in CS Education Eric Roberts emphasizes the student-friendly exposition that led to the success of The Art and Science of C. By......一起来看看 《The Art and Science of Java》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换