Pages

Wednesday, 14 May 2014

Swig-一个基于nodejs的模板引擎


A simple, powerful, and extendable JavaScript Template Engine.
Current Version: v1.3.2. Looking for an older version?

Super Quick Start

For a more in-depth intro, check out the Getting Started docs.

Install Swig

npm install swig --save

Create Your Template

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

Render Your Template

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

The End Result

<h1>Awesome People</h1>
<ul>
  <li class="first">Paul</li>
  <li>Jim</li>
  <li>Jane</li>
</ul>
 
from  http://paularmstrong.github.io/swig/