Pease Plate is hosted by
SourceForge.net Logo

Pease Plate

Template Structure

This chapter describes the basic structure of the templates used in Pease Plate.

Code and Content

This is plain content.
${this.is.code}
This is plain content again.
${-- And this is a comment. --}

${if: value > 42}
This is plain content that is only shown if the value is greater than 42.
${else}
This is shown otherwise.
${end}

${while: iterator.hasNext}
This content is shown while there are more values available like ${iterator.next}.
${end}

${with-each: $value in values}
This content is written once for each ${$value} in the list of values.
${else}
This content is written if the list of values is null or empty.
${end}

Templates in Pease Plate are just normal text files. There is only one notation that seperates content from code: ${...}.

Anything that's within the curled braces is code, anything what's outside, is content. The example on the right should be self-explaining.

The code blocks usually have two parts: the designator, left of the semicolon, and the expression, right of the semicolon. If there is no semicolon in the block, this is either an empty designator like ${end} or ${else}, or an expression with the default ${print: ...} designator left away.

Expression

The expression is usually some Java-like reference to the data object that you provide with the render method. The expression language offers a lot of features for the special needs of template rendering.

For example, the expression language helps you with handling null values so that you almost never have to check for null. It automatically converts datatypes for you, and it provides a transformer mechanism, that helps you formatting and transforming values.

Check out the Expression Language chapter for a detailed description of all the features of the expression language.

Sometimes it depends on the designator how the expression is parsed. While most of the designators interpret the expression as Java-like code, some designators like ${message: ...} and ${include: ...} interpret the expression their own form. Take a look at the reference. Each designator contains a description of how its expression part is parsed.

Designator

The designator is a keyword that tells the parser how to interpret the expression on its right side and what to do with the result.

There are designators to create output, like ${print: ...} and ${message: ...}, others to control the program flow, like ${if: ...}, ${else}, ${while: ...} and ${with-each: ...}. You can create macros and call them with the ${macro: ...} and ${call: ...} designators, include other templates with ${include: ...} and you can even create your own designators.

You can find a list of all designators in the Reference chapter. For a description of how to create own designators, follow the guide in the Creating Custom Designators chapter.