Getting Started with StringTemplate

ST templates are chunks of text and expressions enclosed in angle brackets: <expression>. (You can also tell it to use $expression$.) ST ignores everything outside the expressions, treating it as just text to spit out. ST is a lightweight library (not a tool or server) with two key classes: StringTemplate and StringTemplateGroup. We can create StringTemplate objects using a string literal in code or load them from a template group file using StringTemplateGroup.

The basic idea behind constructing output is that we create a template and inject it with attributes (any Java object). The expressions within a template feed on these attributes to compute text values. We create nested template hierarchies by injecting ...

Get Language Implementation Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.