grunt-templater

Universal template compiler task for Grunt.

npm install grunt-templater
2 downloads in the last day
240 downloads in the last week
1 370 downloads in the last month

grunt-templater

Universal template compiler task for Grunt. It uses Consolidate under the hood.

Supported template engines

Getting Started

install via npm

npm install grunt-templater

install the template engine you intend to use. For example, if using Jade:

npm install jade

and in your grunt.js file:

grunt.loadNpmTasks('grunt-templater');

Usage

Create a template task in your grunt config. Templater will guess the intended template engine based on the src filename. Pass the engine option to force a specific engine.

grunt.initConfig({
  template: {
    dev: {
      src: 'app/homepage.jade',
      dest: 'dev.html',
      variables: {
        css_url: 'app.css'
        title: 'Hello World'
        pretty: true
      }
    },
    dist: {
      src: 'app/homepage.jade',
      dest: 'dist/index.html',
      variables: {
        css_url: 'app.min.css'
        title: 'Hello Production'
      }
    },
    dynamicVariables: {
      src: 'app/homepage.jade',
      dest: 'dist/index.html',
      variables: function () {
        return {
          css: grunt.file.read('app.min.css'),
          now: new Date()
        }
      }
    }
  },
  ...
});

run with:

grunt template

or for a specific target:

grunt template:dev

src, dest, and variables are required. Engine specific options can also be passed through the variables option. In the case of Jade, pretty: true adds pretty-indentation whitespace to its output.

npm loves you