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

  • 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'); 
    
主站蜘蛛池模板: 临颍县| 盐池县| 同江市| 都安| 延庆县| 黄陵县| 盐边县| 临海市| 玉树县| 深圳市| 普洱| 固始县| 行唐县| 石狮市| 德格县| 梅河口市| 宜川县| 林口县| 临江市| 谷城县| 迭部县| 顺义区| 长宁区| 通山县| 湖口县| 祁阳县| 株洲市| 莫力| 湖南省| 钟山县| 秦安县| 黄平县| 洛川县| 西畴县| 洞口县| 开化县| 石泉县| 凤庆县| 松江区| 崇州市| 甘谷县|