Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

213 lines (148 sloc) 4.22 kb


Asynchronous templates for the browser and node.js


I like Mustache and variants but none of them offers quite what I need.

Use Dust if you want these things:

  • async/streaming operation
  • browser/node compatibility
  • extended Mustache/ctemplate syntax
  • clean, low-level API
  • high performance
  • composable templates

Composable templates?

  Child Title
  Child Content


In Node:

$ npm install dust

To render compiled templates in the browser:

<script src="dust-core-0.3.0.min.js"></script>

Demo & Guide

Extensive docs and a full demo are available at

Unit tests using Jasmine

How to run the unit-tests?

In this distributions of dust, we have unit tests in Jasmine for both the client and the nodejs version. If you want to run the client version just open the html page called specRunner.html located on "test/client/specRunner.html".

In order to run the server distribution of dust, run this command in the terminal: "node test/server/specRunner.js"

pre-requisites for tests on node server version:

  • install nodejs 0.6 or greater
  • install npm
  • install Jasmine test framework (npm install -g jasmine-node)

Dust Helpers

Support logic helper @if

Example 1:

{@if cond="('{x}'.length || '{y}'.length ) || (2 > 3) && {a}-{b} == 9"} render if {:else} render else {/if}

Example 2: @if inside the loop# section

With {@if} helper and {@idx} helper


  • {/people

    With {@if} helper and the {$idx}


  • {/people}

    Example 3: Support exists check in the @if helper

    {@if cond="({{x}} || {{y}}) || (2 > 3) && {a}-{b} == 9"} You {:else} Me {/if}


  • {/people}


    {info} The $idx and $len will only work with maps and does not work within arrays , please use the @idx helper in that case, we think such cases will be rare{info}

    h3. here is a example it works

    sample JSON

    {code} { "fronttest_mapper_two": { "items": [{ "item": "pen" }, { "item": "pencil" }, { "item": "flower" }], "test": "TEST" }, } {code}


    Rendering items in a map

    {! items is a map !} {?items}

    1. {$idx} {$len} {.item}
      {@if cond="{$idx} == {$len}-1"}last{/if} {@if cond="{$idx} == {$len}-1"}last{:else} not last{/if}
    2. {/items}


    Rendering items in a map

    0 3 pen
    1 3 pencil
    2 3 last flowe


    h3. here is example $idx and $len will not work


    "fronttest_mapper_two": {
        "brands": ["b1", "b2", "b3"],


    How to make it work? Use the @idx helper {code} {! brand is a list !} {?brands}

      {#brands size="3"}
    1. {.} {@idx} {.}{@if cond="{.} == {size} - 1"} last {/if}{/idx}
    2. {/brands}


    Rendering brands in a list-------------------------------------------------------

    b1 0
    b2 1
    b3 2 last


    Jump to Line
    Something went wrong with that request. Please try again.