{reference}

A reference is used to insert values from your context (or JSON data) into your template.

{key[|filter1|filterN]}

A reference is a single opening curly brace {, followed by a Dust path, optionally followed by one or more filters, followed by a single closing curly brace }.

A Dust path is one or more Dust keys, separated by dots (.).

A Dust key is one or more of the following characters: a-z, A-Z, _ (underscore), $, 0-9, or -

NOTE: The first character of a reference cannot be 0-9 or -.

{name} is a valid Dust reference.{~n} {0name} is not a valid Dust reference.{~n} {.name} is a valid Dust reference.{~n} {.} is a valid dust reference.{~n} {markup|s}: The |s filter does not escape HTML.{~n} {markup}: HTML is escaped by default. { "name": "name", "0name": "0name", "markup": "<span class=\"highlight\">Markup allowed</span>" }

{! comments !}

A Dust comment is used in a template to include text that will be ignored when the template is rendered.

{! All Dust comments are
multiline comments !}
Comments {! in Dust !}can be used for documentation.{~n} Comments can also be used {! <button>Click me!</button> !}to test or remove features.

{#section/}

A standard section is used to change what level of the context Dust uses to look up values. If the new context is an array, the standard section automatically loops through the array. If an {:else} body is used, its contents are output if the new context does not exist.

{! Outside of the section, Dust looks for values at the root of the JSON context !} The value of name is: {name}{~n} {#extraData} {! Inside this section, Dust looks for values within the extraData object !} Inside the section, the value of name is: {name}{~n} {/extraData} The value of name is: {name}, again.{~n} {#nonExistentContext} This is only output if "nonExistentContext" exists. {:else} Because "nonExistentContext" does not exist, the else body is output. {/nonExistentContext} { "name": "Jimmy", "extraData": { "name": "Kate" } }

A section is a single opening curly brace {, followed by a hash #, followed by a Dust path, followed by a closing curly brace }, followed by some content, then a closing tag using the same Dust path.

Section with content:

{#key}
  Some content
{/key}

Section with {:else} body:

{#key}
  Some content
{:else}
  Some other content, if key doesn't exist in the context.
{/key}

Self-closing section (note: this doesn’t do anything, but is technically valid Dust):

{#key/}

{?exists/}

An exists section is a special type of section that outputs its contents if the value it is referencing exists. The syntax for the exists section is the same as the standard section, but the # is replaced by a ?. However, unlike the standard section, the exists section does not change the context.

{?isReady}Ready!{:else}Wait a minute...{/isReady} { "isReady": false }

{^not-exists/}

A not-exists section is a special type of section that outputs its contents if the value it is referencing does not exist. The syntax for the not exists is the same as the standard section, but the # is replaced by a ^. Unlike the standard section, the not exists section does not change the context.

{^isReady}Not ready yet.{:else}I'm ready to go!{/isReady} { "isReady": false }

{@helper/}

A helper is a special kind of section that executes some JavaScript when it is rendered. For more information on using helpers, see the Dust helpers guide. For more information on writing Dust helpers, see the writing helpers guide.

The answer is {@eq key=answer value=42}42{:else}wrong{/eq}. { "answer": 42 }

{<inline-partial/}

An inline-partial is an inert piece of Dust that can be inserted in one or more places in a Dust template. An inline-partial is inserted using a block. For example use cases of inline-partials and blocks, see the base and override templates guide.

An inline-partial is defined as a single opening curly brace {, follwed by a less than sign &lt;, followed by a name (with the same characters allowed in a Dust key), followed by a single closing curly brace }, followed by some content, followed by a closing tag.

{<classNames}primary hero{/classNames}

A self-closing block is defined as a single opening curly brace {, followed by a plus sign +, followed by the name used in the inline-partial, followed by a forward slash and single closing curly brace /}. Alternatively, a block can have content. A block’s content is output only if a matching inline-partial is not found. For more info, see the base and override templates guide.

{+greeting}Hello!{/greeting} world. {<greeting}Howdy{/greeting} {}

{>partial/}

A partial is used to include one dust template inside of another dust template.

All characters are valid in a template name. However, if the template name includes characters that aren’t allowed in Dust references, you should wrap the template name in quotes when including it as a partial.

Basic example:

{> my_template /}
{> "my template name has *special* characters" /}

With parameters:

{> my_template_with_params foo="bar" contacts=friends /}
You want to know if I'm ready? {>exists/} { "isReady": "totally" }

{~special}

A special is converted to a special character

A special is a single opeing curly brace {, followed by a tilde ~, follwed by any of the characters in a reference, followed by a single closing curly brace }. Dust supports five “specials”:

You{~s}can{~s}add{~s}spaces{~s}and{~n}new-lines with Dust specials.{~n}{~n}Curly braces that are usually reserved for {~lb}dust{~rb} syntax can be created with Dust specials, too. {}

Fork me on GitHub