How to use the twig.extendFilter function in twig

To help you get started, we’ve selected a few twig examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github synox / void-mail / infrastructure / web / web.js View on Github external
app.use(express.urlencoded({extended: false}))
// View engine setup
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'twig')
app.set('twig options', {
	autoescape: true
})

// Application code:
app.use(
	express.static(path.join(__dirname, 'public'), {
		immutable: true,
		maxAge: '1h'
	})
)
Twig.extendFilter('sanitizeHtml', sanitizeHtmlTwigFilter)

app.get('/', (req, res, _next) => {
	res.redirect('/login')
})

app.use('/login', loginRouter)
app.use('/', inboxRouter)

// Catch 404 and forward to error handler
app.use((req, res, next) => {
	next({message: 'page not found', status: 404})
})

// Error handler
app.use((err, req, res, _next) => {
	// Set locals, only providing error in development
github yeoman / doctor / lib / message.js View on Github external
'use strict';
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const ansiStyles = require('ansi-styles');
const Twig = require('twig');

// Add Chalk to Twig
for (const style of Object.keys(ansiStyles)) {
  Twig.extendFilter(style, input => chalk[style](input));
}

exports.get = (message, data) => {
  const fileTemplate = fs.readFileSync(path.join(__dirname, 'messages', `${message}.twig`), 'utf8');
  return Twig.twig({data: fileTemplate}).render(data);
};
github engineer-man / emkc / platform / api / services / twig.js View on Github external
const moment = require('moment');

require('twig')
    .extendFilter('noscript', value => {
        if (!value) return value;
        return value.replace(/\//gi, '\\/');
    });

module.exports = {

    starts_with(string, path) {
        var pattern = new RegExp('^' + string.replace('/', '\\/'));

        return pattern.test(path);
    }

};
github codex-team / hawk / hawk / modules / twig.js View on Github external
*/
  twig.extendFunction('svg', function (path) {
    return fs.readFileSync(__dirname + '/..' + path, 'utf-8');
  });


  /**
   * Function for getting full named event-type
   *
   * @usage {{ event.tag | event-type }}
   *
   * @param eventTag - 'fatal', 'warnings', 'notice' or 'javascript' type of error
   *
   * @returns {String} - full named event-type
   */
  twig.extendFilter('event-type', function (eventTag) {
    switch (eventTag) {
      case 'fatal':
        return 'Fatal Error';
      case 'warnings':
        return 'Warning';
      case 'notice':
        return 'Notice';
      case 'javascript':
        return 'JavaScript Error';
    }
  });
}();
github zimmen / gulp-twig / index.js View on Github external
options.filters.forEach(function (filter) {
                Twig.extendFilter(filter.name, filter.func);
            });
        }
github stefanullinger / grunt-twig-render / tasks / twigRender.js View on Github external
Object.keys(this.options.filters).forEach(function(name) {
      var fn = this.options.filters[name];
      if (!isFunction(fn)) {
        grunt.fail.fatal('"' + name + '" needs to be a function!');
      }
      Twig.extendFilter(name, fn);
    }.bind(this));
github radiocity / twig-html-loader / index.js View on Github external
      Object.entries(query.filters).forEach(([name, fn]) => Twig.extendFilter(name, fn));
    }