Filters

Filters are used to transform a variable before outputting it. You can pipe a variable through one or more filters using the | character.

Learn more about filters in Dust.js.

Built-in Filters

Dust.js ships with the following built-in filters.

  • h – HTML-encode a string
  • s – turn off automatic HTML encoding
  • j – JavaScript-encode a string
  • u – encodeURI
  • uc – encodeURIComponent
  • js – JSON.stringify
  • jp – JSON.parse

Example:

{title}
{title|s}
{title|js|s}

Custom Filters

Postleaf provides a handful of additional filters that are useful for converting variables to and from HTML.

  • htmlToText – convert an HTML string to plain text
  • markdownToHtml – convert a markdown string to HTML
  • markdownToText – convert a markdown string to text

Example:

{author.bio|markdownToText}
{tag.description|markdownToHtml|s}

Gotchas

Filters can be applied to variables, but not helpers. This is perfectly valid:

{title|u}

But this is not:

{@date format="YYYY"|u/} - incorrect!