[stringtemplate-interest] Limited control flow with stringtemplate - by design?

Terence Parr parrt at cs.usfca.edu
Tue Nov 15 11:35:14 PST 2005


Howdy. :)  Yep, you cannot test the value of an attribute and not  
include logic in your template.

To handle different templates per type, you can send in a template  
name as an attribute and then do this:

$data:(templateName)()$

to invoke it like an indirect function call.  It applies the named  
template to the data element.

Also, if you want to change how doubles are displayed depending on  
the locale of the incoming web request, then it's the controller's  
job not the template to decide the format *name*.  It can pass that  
name to the page template.  Or, it can wrap objects in something  
whose toString() knows how to alter the format depending on locale.   
Or, register a renderer that knows how to display Double objects  
depending on locale :)

Does this help?

Ter


More information about the stringtemplate-interest mailing list