[stringtemplate-interest] Re : Helpers

Brian Clapper bmc at clapper.org
Thu Oct 21 09:41:03 PDT 2010


On 10/21/10 12:34 PM, Matthieu Wipliez wrote:
> Hi Philip,
> 
> You cannot perform arithmetic computations with StringTemplate, so these must be 
> put in the model:
> 
> 1) I would say add a method isEven() in the model and use
> class="$if (row.even)$even$else$odd$endif$"
> 
> 2) You must define a method getHalfPrice() { return price / 2; }
> and use it in the template.

There's a third option: Use the explicit StringTemplate support for alternating
values. See

http://www.antlr.org/wiki/display/ST/Expressions#Expressions-ApplyingAlternatingTemplatesToMultiValuedAttributes
-- 
-Brian

Brian Clapper, http://www.clapper.org/bmc/
Beauty and harmony are as necessary to you as the very breath of life.


More information about the stringtemplate-interest mailing list