[stringtemplate-interest] Re : Helpers

Matthieu Wipliez mwipliez at yahoo.fr
Thu Oct 21 09:34:15 PDT 2010


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.

Cheers
Matthieu



----- Message d'origine ----
> De : Phillip Neumann <pneumann at gmail.com>
> À : stringtemplate-interest at antlr.org
> Envoyé le : Jeu 21 octobre 2010, 18h 07min 14s
> Objet : [stringtemplate-interest] Helpers
> 
> Hello all,
> 
> Im trying to use ST in a project, for generating HTML and have  two questions
> 
> 1) Im drawing a html table, and need to put class=odd or  class=even in the 
>rows.
>     Whats the correct way to do  this?
> 
> 2) I have a object $obj.Price$ and need to show the half of  it.
>    Can i do something like $obj.Price/2$ ?
> 
> I've hear this  would break the logic/view separation stringtemplate uses.
> 
> What would be  the correct way to do this?
> 
> Thanks in advance,
> -- 
> 
> 
> __________________
> Phillip Neumann
> pneumann at gmail.com
> _______________________________________________
> stringtemplate-interest  mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
> 


      


More information about the stringtemplate-interest mailing list