Question

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

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

module.exports.swig = {

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

};

But it doesn't work, view in the browser look like this:

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

So, tags wasn't interpreted. Is my config file wrong? Standard tags {% ... &} works fine.

Was it helpful?

Solution

Something like this should work: in your 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 the config/swig.js and module.exports.swig, I don't think it's being processed automatically.

OTHER TIPS

if someone need to change the scape var like me (is better to work with swig and angular) just need change or add varControls to the config object

engine: {
  ext: 'swig',
  fn: function (pathName, locals, cb) {
    var swig = require('swig');
    swig.setDefaults({varControls: ['[[', ']]']});
    return swig.renderFile(pathName, locals, cb);
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top