Simple and powerful swig. js, simple and powerful swig. js

Source: Internet
Author: User

Simple and powerful swig. js, simple and powerful swig. js
Swig. js

A simple, powerful, and extendable JavaScript Template Engine.

Summary: JS template engine.

Why to use
  • Rendering pages based on lujin
  • Object-oriented template inheritance makes pages more reusable
  • Dynamic page
  • Quick Start
  • Powerful functions
  • Others
How to use

See swig. js Official Website

Reuse Project Instance pages

Most pages have headers and footer areas, which can be reused by inheriting pages, as follows:
Layout.html

Welcome.html

// Enter {% extends 'according to the actual directory '.. /layout.html '% }{% block content %} <div class = "content-container"> 
Configuration of information and functions

Enterprise information, ownership, business registration number and other information, the information can be stored in the system-params.json, you can also add real-time computing functions, and then through swig. js display and call:
System-params.json:

{"IsDevMode": "true", "corporation": "CCCCCCCC", "ICPNumber": "Shanghai ICP filing xxxxxxxx ",...}

App. js

var systemParams = require('./config/system-params.json'),    swig = require('swig');swig.setDefaults({  cache: !systemParams.isDevMode,  locals: {    now: function () {      return new Date();    },    systemParams: systemParams  }});

Layout.html

Integration of Express. js and Require. js

In Express. js, a page is rendered through swig. js. The required js is loaded in the form of require. js require (deps, callback) in the page:
App. js

app.engine('html', swig.renderFile);app.set('view engine', 'html');app.set('views', __dirname + '/views');

Routers. js

module.exports = [{  path: '/',  view: 'default/welcome',  data: {    title: 'welcome',    requireScripts: [      'controllers/default/welcome-controller'    ],    styles: [      'default/welcome.css'    ]  }}];

Config-routers.js

var routers = require('./routers');...for ... {  ...  router.get(routers[i].path, function(req, res) {    res.render(routers[i].view, routers[i].data, routers[i].callback);  });}

Layout.html

<Html> 

Bootstrap. js

// add others jsGlobalConfig.requireScripts.push('...');requirejs(GlobalConfig.requireScripts, function () {  // todo}
Others

Super Quick Start:
Swig. js docs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.