官术网_书友最值得收藏!

Installing the Swig template engine

The first step to do is to change the default express template engine to use Swig, a pretty simple template engine very flexible and stable, also offers us a syntax very similar to AngularJS which denotes expressions just by using double curly brackets {{ variableName }}.

Tip

More information about Swig can be found on the official website at: https://github.com/paularmstrong/swig.

  1. Open the package.json file and replace the jade line with the following:
     "swig": "^1.4.2",
    
  2. Open terminal/shell in project folder and type:
     npm install
    
  3. Before we proceed, let's make some adjustment to app.js, we need to add the Swig module. Open app.js and add the following code, right after the var bodyParser = require('body-parser'); line:
          var swig = require('swig');
    
  4. Replace the default jade template engine line for the following code:
          var swig = new swig.Swig(); 
          app.engine('html', swig.renderFile); 
          app.set('view engine', 'html'); 
    
主站蜘蛛池模板: 永德县| 报价| 长沙市| 金川县| 南木林县| 巴林左旗| 阿尔山市| 通城县| 老河口市| 虎林市| 福建省| 武邑县| 班玛县| 夏津县| 临安市| 吉木萨尔县| 延边| 浦江县| 彭州市| 和平区| 哈尔滨市| 宜兰市| 奉节县| 南昌县| 三穗县| 文成县| 金川县| 疏勒县| 瑞安市| 南乐县| 商丘市| 应城市| 紫云| 泰宁县| 沅江市| 都匀市| 攀枝花市| 启东市| 临漳县| 保山市| 安龙县|