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

  • Node.js 6.x Blueprints
  • Fernando Monteiro
  • 144字
  • 2021-07-14 10:35:04

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'); 
    
主站蜘蛛池模板: 洱源县| 湖南省| 德清县| 绿春县| 余江县| 乐山市| 裕民县| 呼玛县| 陆川县| 怀柔区| 绍兴县| 屏南县| 青龙| 平遥县| 外汇| 萨嘎县| 温宿县| 华坪县| 柳江县| 罗山县| 扎赉特旗| 屏边| 安阳市| 花莲县| 广州市| 大田县| 定边县| 福建省| 广西| 南澳县| 黔南| 咸宁市| 西吉县| 吉林市| 洛浦县| 四子王旗| 常山县| 那坡县| 叙永县| 林芝县| 泸水县|