[stringtemplate-interest] Expressions in $if(...)$ statements.

Terence Parr parrt at cs.usfca.edu
Thu May 14 18:40:28 PDT 2009


On May 14, 2009, at 3:07 PM, Magdalin, Vlad wrote:

> Hi,
>
> I’m moving over from NVelocity to ST, and so far really liking the  
> strict separation of concerns. However, there are two areas of  
> functionality that are kind of in a gray area, and I’m wondering if  
> ST supports them:
>
> 1. Boolean operators in if() statements, for example:
>
> $if(someBoolValue AND someOtherBoolValue)$ …
>> $endif$
>
> Is this possible?

not currently...I have to do nested IF now, which is effectively an  
AND...in new version of ST I think it will be alllowed.

> I’m finding myself putting together extra Boolean variables and  
> passing them to the view data, but seems like this type of simple  
> logic does not violate M/V/C separation purity any more than a one- 
> value if statement does.  I’ve found this post (http://www.antlr.org/pipermail/stringtemplate-interest/2005-June/000055.html 
> ) from Terence, but can’t seem to find if anything ever came of it.

not yet ;)

>
> 2. Simple arithmetic operations that resolve to a boolean:
>
> $if(items.Count == 1)$
>> $endif$
>
> Right now, I’m finding myself doing things like this to check if a  
> list has one and only one item:

You can do $if(rest(names))$ which asks if it has more than a first  
item.

>
> This zoo contains $zebras.Count$ $if(rest(zebras))$ zebras $else$  
> zebra $endif$
>
> I’m wondering if even simple logic like this doesn’t belong in the  
> view according to the ST methodology.  Any help or insight is  
> appreciated!
>

It's a slippery slope. can't really allow logic in expressions  
involving values.

Ter


More information about the stringtemplate-interest mailing list