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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.