Skip to content
Whiskers templating library for JavaScript
JavaScript CSS
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Whiskers is a templating system focused on template readability. By limiting template logic, the processing and formatting of data is kept separate from the design of its display.

At around 100 lines of code, Whiskers.js may be the smallest mustachioed templating system, compiling templates to pure, incorruptible JavaScript for quick execution. Take a look at the code! It's straightforward and documented.


For the browser, simply source the file at lib/whiskers.js.

For node, npm install whiskers.


Templates are rendered as follows, where "template" is a string and "context" and "partials" are objects:

var rendered = whiskers.render(template, context, partials);

A template might look something like this:

  {if tags}
  <ul id="tags">
    {for tag in tags}
  {!<p>this paragraph is 
    commented out</p>!}

With the following context:

  title: 'My life',
  author: 'Bars Thorman',
  tags: [
  content: 'I grew up into a fine willow.'

And the following partials:

  header: '<h1>{title}</h1>\n<p id="by">{author}</p>'

It would be rendered as this:

    <h1>My life</h1>
    <p id="by">Bars Thorman</p>
  <ul id="tags">
  <div>I grew up into a fine willow.</div>


Whiskers keeps templates readable by limiting tags to variables, statements ("for" and "if"), partials, and comments.

Variable tags retrieve data from the context. They may use dot notation:


A "for" tag loops over variables in an array:

{for variable in array}

An "if" tag only displays a section of the template for a truthy variable, or the inverse:

{if variable}
{if not variable}
  <p>No variable!</p>

As you can see, "for" and "if" sections are closed by a corresponding tag with a leading slash.

A partial tag begins with a greater-than sign. It is replaced by a sub-template at that spot in the template:


Comment tags comment out part of the template. They begin and end with exclamation points. They can include newlines, spaces, and other tags.

<p>{!these words and this {tag} 
  will not be rendered!}</p>

Any tag is escaped from rendering by prepending a backslash:


See the test directory for many usage examples.


Whiskers is influenced by these fine projects:

Something went wrong with that request. Please try again.