Concatenate templates to one object in one file.

npm install grunt-tpl
9 downloads in the last week
44 downloads in the last month


Concatenate templates to one object in one file.

Getting Started

Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-tpl

Then add this line to your project's grunt.js gruntfile:



This task is meant to concatenate templates of any variety to one file with with one object to be compiled client-side.

Project Configuration

This example shows a brief overview of the grunt.js gruntfile config properties used by the tpl task.

// Project configuration.
  tpl: {
    "path/to/concatenated/template-file.js": ["array/of/paths/to/templates/**/*", "/exact/location/of/template.mustache"]

Specify the paths to the concatenated template files as keys. That filename (extension or not) will be used to namespace the Object. The values can be a string or array of strings to relative or absolute paths to your template files. You can use wildcards such as /**/* and /*.js as documented by minimatch.


Assume you have three Mustache templates named a.mustache, b.tpl, and c in a directory test/templates/.


Hello {{a}}




template {{c}}

If you want them concatenated into the file simple/path/t.js, your config would be:

  // ... other configs

  tpl: {
    "simple/path/t.js": ["test/templates/*"]

  // ... other configs


this['t'] = this['t'] || {};

this['t']['a'] = 'Hello {{a}}';

this['t']['b'] = '<ul>{{#items}}  <li>{{.}}</li>{{/items}}</ul>';

this['t']['c'] = 'template {{c}}';

The filenames of your templates will be used as keys in the object

You can then compile these at any time.

var h = Hogan.compile(window.t['a']);


In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

Release History

2013/03/28 - v1.0.0 - Update to grunt 4.0.0.

2012/04/25 - v0.1.0 - Initial release.


Copyright (c) 2013 Licensed under the MIT license.

npm loves you