[stringtemplate-interest] How to fill a <table> grid wise?
John Snyders
jjsnyders at rcn.com
Wed Oct 10 18:49:20 PDT 2007
If it wasn't for a bug or two in passing iterators around I think something like this might work:
group grid;
main() ::= <<
<table>
$rows(items)$
</table>
>>
rows(r) ::= <<
$if(r)$
<tr>
$row(i1=first(r), i2=first(rest(r)), i3=first(rest(rest(r))))$
</tr>
$rows(r=rest(rest(rest(rest(r)))))$
$endif$
>>
row(i1, i2, i3) ::= <<
<td>$i1$</td><td>$i2$</td><td>$i3$</td>
>>
Clearly this gets tedious if the number of columns is more than 3.
I have not downloaded ST in a while so I don't know if the iterator bugs have been fixed or not. I hope they are because it will make many recursive templates possible.
The trouble with a mod function is to be useful it needs comparison operators as in your example and this brings with it the ability for templates to implement business logic - which is bad.
-John
---- Original message ----
>Date: Wed, 10 Oct 2007 17:41:33 -0700
>From: Terence Parr <parrt at cs.usfca.edu>
>Subject: Re: [stringtemplate-interest] How to fill a <table> grid wise?
>To: StoreAdmin <webmaster at storeadmin.com>
>Cc: stringtemplate-interest at antlr.org
>
>Hi. Unfortunately, I can't think of a way in ST directly at the
>moment. I'm adding things slowly like length(attribute) etc... and
>probably a list[i..j] range thing makes sense...hmm...we have first,
>tail, last, etc.... We need a split maybe?
>
>I'm about to push 3.1 so now's the time to speak up ;)
>
>Ter
>On Oct 10, 2007, at 4:58 PM, StoreAdmin wrote:
>
>> Hi,
>>
>> I want to fill items into a table grid-wise: i.e. 3 items per row. The
>> closest solution I can think of is as following:
>>
>> <table>
>> $items : {
>> $if (i % 3 = 1)$ <tr> $endif$
>> <td> $it:item_tmpl()$ </td>
>> $if (i % 3 = 0)$ </tr> $endif$
>> }
>> </table>
>>
>> which needs a mod(%) expression.
>>
>> Is there another way to accomplish this without modifying the ST
>> grammar?
>> _______________________________________________
>> stringtemplate-interest mailing list
>> stringtemplate-interest at antlr.org
>> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
>
>_______________________________________________
>stringtemplate-interest mailing list
>stringtemplate-interest at antlr.org
>http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list