StringTemplate

StringTemplate Articles

Enforcing Strict Model-View Separation in Template Engines
Terence Parr Thu May 20, 2004 13:00
A paper describing what exactly model-view separation means and characterizing the generational power of a template engine that enforces separation; academically-oriented but it's very readable. It was nominated for best paper at the selective WWW2004 conference.

Slides from WWW2004 Conference
Terence Parr Thu May 20, 2004 12:00
Slides from my presentation of the Enforcing Model-View Separation in Template Engines paper.

[DRAFT] A Functional Language For Generating Structured Text
Terence Parr Thu May 11, 2006 10:22
Abstract: This paper describes ST (StringTemplate), a domain-specific functional language for generating structured text from internal data structures that has the flavor of an output grammar. ST's feature set is driven by solving real problems encountered in complicated systems such as ANTLR version 3's retargetable code generator. Features include template group inheritance, template polymorphism, lazy evaluation, recursion, output auto-indentation, and the new notions of group interfaces and template regions. Experience shows that ST is easy to learn and satisfying to use.

ST's primary contribution is the clear identification and implementation of a tightly-bracketed solution to the problem of rendering data structures to text, as dictated by the nature of generation and the critical goal of strictly separating the generation logic from the output templates. First, the very nature of code generation suggests the use of a generational grammar. Next, enforcing separation of the generation logic from the output templates restricts the template language syntactically and semantically in such way that templates are easily shown to be equivalent to a grammar. Finally, the rules of separation, such as side-effect free expressions, coincide with the fundamentals of pure, functional programming.

The Internationalization and Localization of Web Applications
Terence Parr Tue Feb 21, 2006 11:49
A template engine that strictly enforces model-view separation has been shown to be at least as expressive as a context free grammar allowing the engine to, for example, easily generate any file describable by an XML DTD. When faced with supporting internationalized web applications, however, template engine designers have backed off from enforcing strict separation, allowing unrestricted embedded code segments because it was unclear how localization could otherwise occur. The consequence, unfortunately, is that each reference to a localized data value, such as a date or monetary value, replicates essentially the same snippet of code thousands of times across hundreds of templates for a large site. The potential for cut-and-paste induced bugs and the duplication of code proves a maintenance nightmare. Moreover, page designers are ill-equipped to deal with code fragments. But the difficult question remains: How can localization be done without allowing unrestricted embedded code segments that open the door to model-view entanglement? The answer is simply to automate the localization of data values, thus, avoiding code duplication, making it easier on the developer and designer, and reducing opportunities for the introduction of bugs--all-the-while maintaining the sanctity of strict model-view separation. This paper describes how the StringTemplate template engine strictly enforces model-view separation while handily supporting internationalized web application architectures. Demonstrations of page text localization, locale-specific site designs, and automatic data localization are provided.

The Importance of Model-View Separation (a conversation with Terence Parr)
Bill Venners Fri Mar 21, 2008 08:56
In this interview with Artima, Terence Parr, creator of the StringTemplate template engine as well as the ANTLR parser generator, talks about the importance of separating business logic and presentation.

Using a Template Engine from your Java code
Doug Breaux (Submitted by TJP) Sat Aug 25, 2012 13:33
However, we now have a desire to capture merged HTML into standalone files that are not related to HTTP request or response processing. So rather than hardcode the HTML creation, I decided to start using one of the existing template engines. Velocity, FreeMarker, and StringTemplate are 3 of the most used. One of my main requirements was that the template files be true HTML that would syntax-check successfully in an IDE or code editor...

Localizable text template engine using StringTemplate 4
Andrew Malkov [posted by parrt] Tue Apr 24, 2012 09:29


StringTemplate als Java Template Engine f�r mehrsprachige, formatierte Text-Emails
Christian Schiestl Thu Aug 11, 2011 09:46
An article in German. English version

StringTemplate: a great template engine for code generation
Pedro J. Molina [submitted by Terence] Fri Nov 26, 2010 08:05
In this post, I will try to introduce and explain why StringTemplate is a superb engine for doing code generation and why you should consider it if dealing with a code generation scenario.

ST Part 4:Generating a Builder Class using StringTemplate
Collin Fagan Sun Jun 13, 2010 15:12


ST Part 3: Complex Data Types and Renderers
Collin Fagan Tue Jun 8, 2010 11:39


ST: Collections and Template Groups
Collin Fagan Thu Jun 3, 2010 11:41


An introduction to StringTemplate
Collin Fagan Thu Jun 3, 2010 11:40
A quick introduction to ST generating SQL.

Generating Structured Text with StringTemplate
Michael Ceranski [submitted by Terence] Mon Feb 8, 2010 12:34
In order to get familiar with the functionality lets start by looking at a few sample templates...

Clojure and StringTemplate
submitted by Terence Parr Fri Jan 22, 2010 16:14
An example using ST in Clojure.

StringTemplate ? a step forward to a better web MVC
Ran Tavory Thu Nov 19, 2009 12:18
StringTemplate is a step forward true MVC implementation, but before presenting the solution, let?s see what the problem is....

Using StringTemplate as a ViewEngine for ASP.Net MVC
Website Logic, LLC Wed Aug 12, 2009 12:52
After kicking the tires on every ViewEngine I could get my hands on (including hacking my own template language just for fun), I became frustrated with endless pages of "tag soup". My search for something lightweight, fast, easy to read, and wrist friendly led me to a solid product called StringTemplate.

Using StringTemplate as the view engine for your Spring MVC application
Nick Carroll Thu Jun 18, 2009 11:19
You can use StringTemplate to generate your views in Spring MVC quite easily.

Using StringTemplate with J2EE
Richard Barabe Mon Mar 9, 2009 22:52
Here is a brief example of using StringTemplate in a j2ee environment. StringTemplate can play the role of the view in a J2EE web application, and can be used as a replacement for JSP/JSTL.

Which Java MVC frameworks integrate easily with StringTemplate?
submitted by Terence Fri Feb 20, 2009 09:00
A few code snippets showing ST use with Spring.

Using StringTemplate as a ViewEngine for ASP.Net MVC
Jamison Morrow Sun Feb 15, 2009 18:02
An article describing the basics of using StringTemplate as a View Engine for the ASP.Net MVC Framework.

Script injection and StringTemplate
John Snyders Fri Feb 15, 2008 19:13
Some thoughts on rendering in StringTemplate. What can be done to protect against script injection in HTML without the template author needing to be aware of escaping rules?

Setting up ANTLR/ST for use with Matlab
L & D Engineering LLC Sun Dec 2, 2007 11:11


Refactoring your Templates
Sander Hahn Sat Oct 13, 2007 08:55
Chronicles Sander's use of ST.

Thoughts on StringTemplate
John Snyders Wed Jun 27, 2007 17:59
Second in a series of articles on ideas for the future of StringTemplate. Part 2 is about programming-in-the-large.

Required Reading: Enforcing Strict Model-View Separation in Template Engines
David Rupp Wed Jun 6, 2007 16:01
Blog entry discussing Enforcing Strict Model-View Separation in Template Engines.

Chinese version: Enforcing Strict Model-View-Separation in Template Engines
Translated by Richie Liu Tue Jun 5, 2007 11:39
I translated the paper into Chinese and post it there, is to bring it to Chinese programmers, and make it more readable to us.

On Learning StringTemplate
John Snyders Thu Apr 26, 2007 10:46
I have been thinking lately about the learnability (the ease with which something can be learned) of StringTemplate. StringTemplate needs is a literal representation for data that can be used as input and a stand alone program to read the data and templates to produce the output text. I created a command line tool called StringTemplate Standalone Tool (STST). It takes as input the name of a file containing data in JSON format, the name of a template and optionally the name of a group as well as various options.

Web app investigation part 2 - StringTemplate
John Snyders Tue Mar 27, 2007 15:58
This post will describe my experience with StringTemplate. I also give some informal performance numbers.

Grokking StringTemplate
Ian Rae Tue Feb 13, 2007 14:57
The blog has conclusions after a couple of days of playing with StringTemplate in Java.

John Snyders' blog entry on ST
John Snyders Mon Dec 11, 2006 09:43
Talks about using ST in a simple website, comparing to hand-coded servlet and JSF. ST's speed is in between those two.

Terence Parr on Strict Model-View Separation in Templates
Terence Parr Wed Oct 18, 2006 10:39
An interview I did for Artima.com :)

Intelligent Web Site Page Generation
Terence Parr Fri Jul 7, 2006 14:30
Discussing factoring code for building dynamic web sites and other issues related to page design.

Using StringTemplate in Page classes
Terence Parr Fri Jul 7, 2006 14:29
How to integrate ST into some servlets; look near the bottom of the page.

The Role of Template Engines in Code Generation
Terence Parr Fri Jul 7, 2006 09:36
A multimedia version of my presentation at Microsoft Research in July of 2004.

Slides from BEA Presentation
Terence Parr Fri Apr 1, 2005 17:37
Jean Bovet and I went to BEA to show off StringTemplate, ANTLR, and ANTLRWorks.

The Evolution of the StringTemplate Engine
Terence Parr Wed Dec 15, 2004 13:00
Slides from my presentation at UC Berkeley's Harmonia group

Generating Java and XML Using StringTemplate
Terence Parr Wed Aug 18, 2004 10:00
This small article demonstrates how a Java program may dump out its own field/method interface as Java text using reflection and then generate the interface in XML--all without changing the generation logic.

The Role Of Template Engines in Code Generation
Terence Parr Sun Jul 25, 2004 10:00
Slides from my presentation at Microsoft Research.