[stringtemplate-interest] Check attribute list length or empty list

Terence Parr parrt at cs.usfca.edu
Mon Apr 4 17:11:57 PDT 2011


done. updated doc.
Ter
On Mar 30, 2011, at 12:08 AM, Udo Borkowski wrote:

> the following template will emit the expected result (i.e. only write the "select" when there are items in column):
> 
> $if(column)$
>     select $column; separator=","$
> $endif$
> 
> (in StringTemplate 4.0, not sure about older versions)
> 
> @Ter: you may want to update the ST4 documentation at http://www.antlr.org/wiki/display/ST4/Templates#Templates-conditionals: beside the stuff you mention ST4 also returns false for empty lists and maps as well a "empty" iterators (see Interpreter.testAttributeTrue).
> 
> Udo
> 
> 
> 
> On 30.03.2011, at 05:48, guk guk wrote:
> 
>> Hi !
>> 
>> I'm trying to check the length of the column list but it keep throwing an error.
>> How to check if an attribute has value on it or not ?
>>   
>> $if(length(strip(column)) >  0)
>>                 select $column; separator=\",\"$
>>  $endif$
>> 
>> Thanks for your help 
>> 
>> _______________________________________________
>> stringtemplate-interest mailing list
>> stringtemplate-interest at antlr.org
>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
> 
> _______________________________________________
> 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