• This repository has been archived on 11/Apr/2018
  • Stars
    star
    3,110
  • Rank 13,816 (Top 0.3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 12 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Take a swig of the best template engine for JavaScript.

NOT MAINTAINED

Fork and use at your own risk.

Swig Build Status Dependency Status NPM version NPM Downloads

Swig is an awesome, Django/Jinja-like template engine for node.js.

Features

  • Available for node.js and major web browsers!
  • Express compatible.
  • Object-Oriented template inheritance.
  • Apply filters and transformations to output in your templates.
  • Automatically escapes all output for safe HTML rendering.
  • Lots of iteration and conditionals supported.
  • Robust without the bloat.
  • Extendable and customizable. See Swig-Extras for some examples.
  • Great code coverage.

Need Help? Have Questions? Comments?

Installation

npm install swig

Documentation

All documentation can be viewed online on the Swig Website.

Basic Example

Template code

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

node.js code

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

Output

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

For working example see examples/basic

How it works

Swig reads template files and translates them into cached javascript functions. When we later render a template we call the evaluated function, passing a context object as an argument.

License

Copyright (c) 2010-2013 Paul Armstrong

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

normalizr

Normalizes nested JSON according to a schema
JavaScript
20,970
star
2

build-tracker

A set of tools to track the size of your build artifacts over time.
TypeScript
437
star
3

react-component-benchmark

A component to help benchmark React components and their trees.
TypeScript
378
star
4

onerepo

Easy, strict, safe, and fast JavaScript & TypeScript monorepo toolchain for high performance teams.
TypeScript
106
star
5

node-templates

Benchmarking various Node.js template engines
JavaScript
97
star
6

swig-extras

A collection of handy tags, filters, and extensions for Swig, the most awesome template engine for node.js.
JavaScript
71
star
7

basejs

baseJS is a work-in-progress lightweight JavaScript library for Safari, Firefox, and especially Mobile Safari. Be sure to run 'git submodule init' and 'git submodule update' upon first clone of baseJS to get Sizzle imported.
JavaScript
59
star
8

mocha-to-jest-codemod

Convert Mochan TDD with Chai assert tests to Jest
JavaScript
42
star
9

monorepo-ts

A git repo template for setting up TypeScript Monorepos
JavaScript
39
star
10

react-stateful-firestore

Bindings to provide authentication and access to Firestore data in React.
JavaScript
20
star
11

dotfiles

My setup and config files.
Shell
19
star
12

still

A static site generator built with node.js
JavaScript
16
star
13

jest-multi-project-example

JavaScript
15
star
14

ImpactJS.tmbundle

A Textmate bundle: snippets, language, and templates for ImpactJs
JavaScript
10
star
15

build-tracker-heroku

Quickly and easily deploy a new Build Tracker application to Heroku
JavaScript
8
star
16

ImpactTest

A wrapper to allow unit testing of Impact.js through Node.js
JavaScript
8
star
17

paularmstrong.dev

Paul is a Principal Software Engineer with deep experience leading teams and building amazing experiences using many different “front-end” web technologies. The list is deep and topics can range from JavaScript, Typescript, Node.js, React, CSS, PWAs, developer experience, testing, continuous integration, and more. This is his website’s github repo.
MDX
8
star
18

build-tracker-action

GitHub Action for adding Build Tracker comparisons to pull requests
JavaScript
6
star
19

Swig.tmbundle

A Textmate Bundle for Swig.
5
star
20

CSSlider

A Slideshow tool built with HTML, JS, and CSS3
JavaScript
5
star
21

node-web-boilerplate

JavaScript
5
star
22

remove-aliasing

Remove module import aliasing from your codebase
JavaScript
4
star
23

photobooth

Take photos and videos using any webcam and a 6-button Elgato Streamdeck.
TypeScript
4
star
24

JSGestureRecognizer

Touch gesture events for the DOM.
JavaScript
3
star
25

nko-jackalope-promo

Promo Page for Node Knockout Jackalope project
JavaScript
3
star
26

reui

reUI is a set of reusable react components using Tailwindcss and react-aria
TypeScript
2
star
27

LabelOver

A jQuery plugin that handles dynamically placing an HTML label over its associated input.
JavaScript
2
star
28

react-component-benchmark-example

Created with CodeSandbox
TypeScript
2
star
29

babel-plugin-transform-stateless-jsx-calls

JavaScript
1
star
30

commandapp

JavaScript
1
star