[stringtemplate-interest] template existence testing

Terence Parr parrt at cs.usfca.edu
Tue Apr 1 11:59:31 PDT 2008


On Mar 31, 2008, at 3:41 PM, Zenaan Harkness wrote:
> As you correctly point out, overriding a template is exactly what I  
> want
> to do.
>
> BUT !!  I don't know the name of the template I want to override in
> advance

No problem. use template ref indirection.

<(name)()>	inserts instance of template "x" if "name"->"x" in the  
attribute table

vs

<name()>	inserts  Instance of template called "name"

> ((at least, the view does not know, and the view should not have
> any deep knowledge of the data Model, at least as much as possible,  
> and
> putting this in the view would cause an explosion of data model
> knowledge in the view, where there should be none)),

Yep, the model can push in the name of the template no problem.  I  
have another user that does this very thing to decide how to display  
something.

> As you can see, not only am I currently caused to put very
> model-specific knowledge in my [java|csharp|perl]-lib.stg template
> groups, but it would also obviously cause the unnecessary explosion in
> number of templates mentioned above.

See if the indirection thing helps you.  It gives you a great deal of  
flexibility: you get indirection as well as polymorphism combined :)

Ter


More information about the stringtemplate-interest mailing list