roots extension that precompiles templates for use on the client side
Last updated 5 years ago by jenius .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install client-templates 
SYNC missed versions from official npm registry.

Roots Client Templates

npm tests coverage dependencies

Roots client templates allow templates that compile to html to be precompiled into javascript functions to be used on the client side.

Note: This project is in early development, and versioning is a little different. Read this for more details.


  • make sure you are in your roots project directory

  • npm install client-templates --save

  • modify your file to include the extension, as such

    ClientTemplates = require('client-templates')
    module.exports =
      extensions: [ClientTemplates(
        base: "templates/", # required
        pattern: "*.jade", # defaults to **
        out: "js/templates.js" # defaults to js/templates.js
      # everything else...


This extension uses accord for compilation and includes support for these languages. If you try to use it with an unsupported language, you will get an error and the compile will not complete.

The example provided in the installation section is the minimum required to get things going. In this case it will look for a folder called templates at the root, and precompile any .jade file in that folder, outputting all the templates to js/templates.js in your public folder. Now let's look over the full range of available options.

This extension also exposes a view helper function (client_templates) that when called will render the script into your templates automatically. Here's how it could be used in jade:

p here's my great view
!= client_templates() //- outputs <script src='js/templates.js'></script>



This will be the name your templates are exposed as. If you are using commonjs or amd, it will be the name of the module, if neither, it will be attached to window as this name. Default is templates.


A minimatch-compatible string pointing to one or more files to be precompiled.


Where you want to output your templates to in your public folder (or whatever you have set output to in the roots settings). Default is js/templates.js


If false in addition to being precompiled, templates are compiled normally as html files. Default is true.


If true, the precompiled templates are concatenated into a single file with helpers at the top, wrapped with a [umd] wrapper, and each template is exported on an object with they key being the name of the file (minus extension). If false, each template is exported with a umd wrapper as it's own file as expected, and the helper functions (required to render templates) are exported alone in a file with the name decided by what you pass as out. Default is true.

License & Contributing

Current Tags

  • 0.2.0                                ...           latest (5 years ago)

12 Versions

  • 0.2.0                                ...           5 years ago
  • 0.1.3                                ...           5 years ago
  • 0.1.2                                ...           6 years ago
  • 0.1.1                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
  • 0.0.7                                ...           6 years ago
  • 0.0.6                                ...           6 years ago
  • 0.0.5                                ...           6 years ago
  • 0.0.4                                ...           6 years ago
  • 0.0.3                                ...           6 years ago
  • 0.0.2                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (6)
Dev Dependencies (9)
Dependents (1)

Copyright 2014 - 2017 © |