How to use the twig.extendFunction 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 zimmen / gulp-twig / index.js View on Github external
options.functions.forEach(function (func) {
                Twig.extendFunction(func.name, func.func);
            });
        }
github codex-team / hawk / hawk / modules / twig.js View on Github external
module.exports = function () {
  'use strict';

  /**
   * Function for include svg on page
   *
   * @example svg('path/from/root/dir')
   *
   * @param path - path from project root dir
   *
   * TODO: location independence
   *
   * @returns {String} - svg code
   *
   */
  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':
github stefanullinger / grunt-twig-render / tasks / twigRender.js View on Github external
Object.keys(this.options.functions).forEach(function(name) {
      var fn = this.options.functions[name];
      if (!isFunction(fn)) {
        grunt.fail.fatal('"' + name + '" needs to be a function!');
      }
      Twig.extendFunction(name, fn);
    }.bind(this));
github radiocity / twig-html-loader / index.js View on Github external
      Object.entries(query.functions).forEach(([name, fn]) => Twig.extendFunction(name, fn));
    }