Swig engine template and Sails.js - how to change tagControls

I want to change the default Swig tagControls {% ...%} to {? ...?} I am using the sails.js framework.

I add the config folder to the swig.js file, which contains:

module.exports.swig = {

  SwigOpts: {
    'tagControls':  ['{?', '?}']
  }

};

But this does not work, viewing in the browser looks like this:

{? for user in users ?}
{? user.email ?}
{? endfor ?}

So the tags were not interpreted. Is my configuration file invalid? Standard tags {% ... &} work fine.

+3
source share
2 answers

Something like this should work: in config/views.js

engine: {
  ext: 'swig', // Or `html`, whatever you are using
  fn: function (pathName, locals, cb) {
    var swig = require('swig');
    swig.setDefaults({tagControls: ['{?', '?}']});
    return swig.renderFile(pathName, locals, cb);
  }
},

As for config/swig.jsand module.exports.swig, I do not think that it is processed automatically.

+6
source

- scape var, ( swig angular), varControls

engine: {
  ext: 'swig',
  fn: function (pathName, locals, cb) {
    var swig = require('swig');
    swig.setDefaults({varControls: ['[[', ']]']});
    return swig.renderFile(pathName, locals, cb);
  }
}
0

All Articles