How to use the twig.twig 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 twigjs / twig.js / demos / twitter_backbone / js / view / tweetView.js View on Github external
, function (require, exports, module) {
        var Backbone = require("backbone")
            , twig = require("twig").twig
        
            // Load the template for a "Tweet"
            //     This template only needs to be loaded once. It will be compiled at
            //     load time and can be rendered separately for each Tweet.
            , template = twig({
                href: 'templates/tweet.twig'
                , async: false
            })
            
            , TweetView = Backbone.View.extend({
                tagName: "li"
                , className: "tweet"

                // Create the Tweet view
                , initialize: function() {
                    // Re-render the tweet if the backing model changes
                    this.model.bind('change', this.render, this);

                    // Remove the Tweet if the backing model is removed.
                    this.model.bind('destroy', this.remove, this);
                }
github stefanullinger / grunt-twig-render / tasks / twigRender.js View on Github external
pathArray = pathArray.concat(elt[flatten]);
            } else {
              pathArray.push(elt);
            }
          }
        }
        for (i = 0, len = pathArray.length; i < len; i++) { 
          var tt = Twig.twig(merge(twigOpts,{path: template}));
          // compute destination path by inserting '_n'
          var destPath = dest.replace(/(.*)(\.[^\.]+)$/, replacer);
          actualData.dataPath = pathArray[i];
          grunt.file.write(destPath, tt.render(actualData));
        }
        actualData.dataPath = pathArray;
      } else {
        var twigTemplate = Twig.twig(merge(twigOpts,{path: template}));
        grunt.file.write(dest, twigTemplate.render(actualData));
      }
    }
  };
github twigjs / twig.js / demos / twitter_backbone / js / view / appView.js View on Github external
, function (require, exports, module) {
        var twig = require("twig").twig
            , Backbone = require("backbone")
            , feed = require("feed").feed

            // The application template
            , template = twig({
                href: 'templates/app.twig'
                , async: false
            })
            
            , FeedView = require("feedView").FeedView
            , feedView = new FeedView

            , AppView = Backbone.View.extend({
                tagName: "div"
                , className: "app"

                // Bind to the buttons in the template
                , events: {
                    "click .reloadTweets": "reload"
                    , "click .changeUser": "changeUser"
                    , "click .twitter_user": "twitterLink"
github shopware / platform / src / Administration / Resources / administration / src / core / factory / template.factory.js View on Github external
if (!template.baseTemplate) {
        // build baseTemplate form parent component
        if (template.extendsFrom) {
            let templateConfig = {};

            if (hasBlocks(template.extendsFrom)) {
                // use baseTemplate from parent component
                const extendTemplate = templateRegistry.get(template.extendsFrom);

                templateConfig = {
                    id: `${componentName}-baseTemplate`,
                    data: extendTemplate.baseTemplate.tokens
                };

                template.baseTemplate = Twig.twig(templateConfig);
            } else if (template.overrides.length > 0) {
                // use first override as baseTemplate
                // and remove it from overrides
                const firstOverride = template.overrides.shift();

                template.baseTemplate = firstOverride;
            } else {
                warn(componentName, 'has no overrides or template to extend from!');
                return '';
            }
        } else {
            warn('missing baseTemplate', componentName);
            return '';
        }
    }
github namics / generator-nitro / packages / project-nitro-twig / app / templating / twig / utils.js View on Github external
function logAndRenderError(error) {
	console.warn(error.message);

	const template = Twig.twig({
		data: '<p class="nitro-msg nitro-msg--error">{{ message }}</p>',
	});

	return template.render({ message: error.message});
}
github engineer-man / emkc / platform / api / services / views.js View on Github external
.fcall(() => {
                return twig
                    .twig({
                        allowInlineIncludes: true,
                        base: root_dir + '/platform/views',
                        path: root_dir + '/platform/views/' + template + '.twig',
                        async: false
                    })
                    .render(data);
            });
    }
github shopware / administration / Resources / app / administration / build / nuxt-component-library / lib / file-parser / twig-components / index.js View on Github external
function extractBlocks(file, content) {    
    const template = Twig.twig({
        id: file.source.name,
        data: content
    });

    const templateBlocks = template.render({}, {
        output: 'blocks'
    });

    return Object.keys(templateBlocks).map((key) => {
        const template = templateBlocks[key];

        return {
            name: key,
            template: pretty(template, { ocd: true })
        };
    });
github yeoman / doctor / lib / message.js View on Github external
exports.get = (message, data) => {
  const fileTemplate = fs.readFileSync(path.join(__dirname, 'messages', `${message}.twig`), 'utf8');
  return Twig.twig({data: fileTemplate}).render(data);
};
github popeindustries / buddy / packages / buddy-plugin-twig / index.js View on Github external
exports.compile = function (content, options, fn) {
  try {
    const template = twig({
      path: options.filepath,
      base: path.dirname(options.filepath),
      async: false
    });

    fn(null, template.render(options));
  } catch (err) {
    err.filepath = options.filepath;
    fn(err);
  }
};
github dpc-sdp / ripple / src / scripts / generate-readme / generate-readme.js View on Github external
},
  description: {
    start: '',
    end: '',
    twig: Twig.twig({
      data: fs.readFileSync(path.join(__dirname, '/template_description.md'), 'utf-8')
    }),
    generate: (packageJSON, directory) =&gt; {
      let description = wrap(packageJSON.description)
      return stripHtmlComments(tags.description.twig.render({ packageDescription: description }))
    }
  },
  install: {
    start: '',
    end: '',
    twig: Twig.twig({
      data: fs.readFileSync(path.join(__dirname, '/template_install.md'), 'utf-8')
    }),
    generate: (packageJSON, directory) =&gt; {
      return stripHtmlComments(tags.install.twig.render({ packageName: packageJSON.name }))
    }
  },
  dependencygraph: {
    start: '',
    end: '',
    twig: Twig.twig({
      data: fs.readFileSync(path.join(__dirname, '/template_dependency_graph.md'), 'utf-8')
    }),
    generate: (packageJSON, directory) =&gt; {
      let dependencyGraph = ''
      let deps = []
      for (let key in packageJSON.dependencies) {