Templates may reference components that live in different namespaces.

Using components

Components are referenced from a template and it’s possible to pass attributes and parameters to it.

Attributes are passed via the opening XML-element:

... xmlns:d="dust:common" ...

<d:if test="${test}">

Parameters are passed via XML-elements in the namespace dust:parameters:

... xmlns:p="dust:parameters" ...


More about the standard components

Creating a component

Classes are regular classes that are annotated with @Component. Components are automatically discovered within registered namespaces.

Here is a tiny component that says hello to a user:

public class HelloComponent {
	private String name;

	public void prepare(@TemplateParam("name") String name) { = name;

	public String getName() {
		return name;

With a template named HelloComponent.xml in the same package:

<span xmlns:d="dust:common">
	Hello ${name}!

	<d:if test="${name == 'Cookie monster'}">
		Your name is awesome!

Calling this component:

<namespace:hello name="your name here" />



Methods annotated with @PrepareRender are called just before a component is rendered. If several methods are annotated Dust will select the best one to invoke. This is useful to allow for several ways to use a components, such as follows:

public void prepare(@TemplateParam("names") List<String> name) { /* ... */ }

public void prepare(@TemplateParam("name") String name) { /* ... */ }


This annotation is used to receive a value from the calling template. This can either be used with @PrepareRender or on a setter method.