[stringtemplate-interest] Conditional statements

Kay Roepke kroepke at dolphin-services.de
Sat May 6 16:53:26 PDT 2006


On 7. May 2006, at 1:31 Uhr, Sohail Somani wrote:

> I'm still unclear as to how ST allows the view to generate a table  
> with
> alternating row/column colours. Is there an example of this?

It's right there in The Fine Manual:

[http://www.stringtemplate.org/doc/doc.tml] approx halfway through:
----------
Applying Alternating Templates To Multi-Valued Attributes

When generating lists of things, you often need to change the color  
or other formatting instructions depending on the list position. For  
example, you might want to alternate the color of the background for  
the elements of a list. The easiest and most natural way to specify  
this is with an alternating list of templates to apply to an  
expression of the form: $expr:t1(),t2(),...,tN()$. To make an  
alternating list of blue and green names, you might say:

$names:blueListItem(),greenListItem()$

where presumably blueListItem template is an HTML <table> or  
something that lets you change background color. names[0] would get  
blueListItem() applied to it, names[1] would get greenListItem(), and  
names[2] would get blueListItem(), etc...

If names is single-valued, then blueListItem() is applied and that's it.

------------


> The obvious way would be something like:
>
> if(($i0$ % |items|)==0) something
> else something else

That way dragons live! ;)

HTH,
-k


More information about the stringtemplate-interest mailing list