node package manager



This node.js package is supposed to ease the process of building websites based on templates.

This documentation is incomplete. Please take a look at the examples .


npm install templatejs


Files & Syntax

template.js uses two kinds of files.

  • Template files contain the file structure. Beneath static content they can reference other files and declare dynamic fields.
  • Input files contain dynamic content. There may be multiple input files for a single output file.


There are three different types of codes. Each has multiple possible syntaxes.

  1. Include other files:
    {{ include FILE }}
    {{ # FILE }}
  2. Include dynamic content:
    {{ declare NAME }}
    {{ + NAME }}
  3. Define dynamic content:
    {{ NAME }}...{{ end NAME }}
    {{ NAME }}...{{ $ NAME }}
    {{ NAME: ... }}

It is possible (and often useful) to wrap these codes in comments. For this purpose template.js determines the programming language the template file is written in. It is also possible to set the language via the --language (-l) parameter which takes 'html', 'javascript' or 'plain' where plain means no comment wrapping. The codes above use the 'plain' syntax.

Syntax examples:

Plain HTML JavaScript
{{ declare title }}
<!-- {{ declare title }} -->
/* {{ declare title }} */
{{ title: Hello world }}
<!-- {{ title: Hello world }} -->
/* {{ title: Hello world }} */
{{ include head }}
<!-- {{ include head.html }} -->
/* {{ include head.js }} */

Command line interface

Try templatejs --help for information

Operation modes

template.js provides two modes of file generation:

  1. Default mode: This mode outputs the template resolving dynamic content. The output file is a valid input file producing the same output as the original input file did.
  2. Production mode: This mode outputs the template without any template.js control codes. The output is not a valid input file but contains only static content. Content insertion and file inclusion will be performed.

To enable the production mode add the -p / --production parameter.



  • Completely rewritten
  • New and powerful syntax
  • Now provides a simple API


  • Increased allowed length of field names.


  • Added 'output' option
  • Fixed UTF8 encoding


  • First release