Dust Filters

Filter call


Function definition

dust.filters.myFilter = function(value) {
  /* Modify the value */
  return value;


Return Value


In this example, we will define a ‘unicorn’ filter, which takes a string and replaces all instances of the word “unicorn” with “horse”, because we don’t believe in unicorns.

JavaScript definition of a Unicorn filter

dust.filters.unicorn = function(value) {
   if (typeof value === 'string') {
      return value.replace('unicorn', 'horse');
    return value;

Unicorn filter usage in a dust template

{! JSON context: {
    myInput: 'I love unicorns'
{! outputs 'I love horses' !}

Fork me on GitHub