[stringtemplate-interest] Can StringTemplate do some control based on attribute type or value?

Todd weidagang2046 at gmail.com
Sun Jun 29 18:17:24 PDT 2008


Take the email template example from http://www.cs.usfca.edu/~parrt/course/601/lectures/stringtemplate.html, I want to get "emails" or "email" in different cases, not a "email(s)" in general. If the $email is muti-valued, I'd like to get "Your emails: aaa,bbb;", otherwise "Your email: aaa". Can ST do some text control within the template based on attribute type(muti-valued or single-valued) or attribute value(for 
example: string length of the attribute value)?



Example From: http://www.cs.usfca.edu/~parrt/course/601/lectures/stringtemplate.html

==========================================================


If your controller sets an attribute more than once, then that attribute is multi-valued.  Imagine the following controller code: 
StringTemplate t =
    new StringTemplate("Your email(s): $email; separator=\", \"$;");
t.setAttribute("email", "parrt at antlr.org");
t.setAttribute("email", "parrt at cs.usfca.edu");

 
where I have specified an optional separator here. 

All elements are converted to text and generated in order. The output would look like: 
Your email(s): parrt at antlr.org, parrt at cs.usfca.edu;


 ==========================================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20080630/bf9038b3/attachment.html 


More information about the stringtemplate-interest mailing list