How to use the nunjucks.Template function in nunjucks

To help you get started, we’ve selected a few nunjucks 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 pangolinjs / core / lib / html / nunjucks-loader.js View on Github external
} else {
      return url
    }
  })

  // Add environment variables as global Nunjucks variable
  env.addGlobal('process', {
    env: {
      NODE_ENV: process.env.NODE_ENV,
      PANGOLIN_ENV: process.env.PANGOLIN_ENV
    }
  })

  // Add Pangolin templates as global Nunjucks variable
  env.addGlobal('pangolin', {
    head: new nunjucks.Template(docsTemplates.head, env).render()
  })

  // Add metadata as global Nunjucks variable
  env.addGlobal('page', pageMeta)
  env.addGlobal('site', siteMeta)

  // Render page and return results via webpack callback
  env.renderString(template, (error, result) => {
    if (error) return callback(error)

    // Pass content to next loader
    callback(null, result)
  })
}
github mozilla / login.webmaker.org / app / http / server.js View on Github external
nunjucksEnv.addFilter("instantiate", function (input) {
    var tmpl = new nunjucks.Template(input);
    return tmpl.render(this.getVariables());
  });
github mozilla / make-valet / server.js View on Github external
nunjucksEnv.addFilter("instantiate", function(input) {
    var tmpl = new nunjucks.Template(input);
    return tmpl.render(this.getVariables());
});
github pangolinjs / core / lib / html / render-nunjucks.js View on Github external
const sidebar = () => {
      let html = new nunjucks.Template(templates.sidebar, env).render({
        components: pageObjects(context, 'components', file),
        prototypes: pageObjects(context, 'prototypes', file)
      })

      return new nunjucks.runtime.SafeString(html)
    }
github pangolinjs / core / lib / html / render-nunjucks.js View on Github external
const components = () => {
      return new nunjucks.Template(templates.components, env)
    }
github pangolinjs / core / lib / html / render-nunjucks.js View on Github external
const footer = () => {
      let html = new nunjucks.Template(templates.footer, env).render()

      return new nunjucks.runtime.SafeString(html)
    }
github mozilla / nunjucks / bench / run.js View on Github external
var fs = require('fs');
var bench = require('bench');
var oldNunjucks = require('nunjucks');
var nunjucks = require('../index');

var src = fs.readFileSync('case.html', 'utf-8');

var oldEnv = new oldNunjucks.Environment(null);
var oldTmpl = new oldNunjucks.Template(src, env, null, null, true);

var env = new nunjucks.Environment(null);
var tmpl = new nunjucks.Template(src, env, null, null, true);

var ctx = {
    items: [
        {
            current: true,
            name: "James"
        },
        { 
            name: "Foo",
            url: "http://example.com"
        },
        { 
            name: "Foo",
github pangolinjs / core / lib / html / render-nunjucks.js View on Github external
const head = () => {
      let html = new nunjucks.Template(templates.head, env).render()

      return new nunjucks.runtime.SafeString(html)
    }
github mozilla / thimble.mozilla.org / services / login.webmaker.org / app / http / server.js View on Github external
nunjucksEnv.addFilter("instantiate", function (input) {
    var tmpl = new nunjucks.Template(input);
    return tmpl.render(this.getVariables());
  });