[stringtemplate-interest] How to fill a <table> grid wise?

John Snyders jjsnyders at rcn.com
Wed Oct 10 19:47:17 PDT 2007


I think the easiest thing to do is change the program generating the data to create a list of lists. 

In JSON format the data would look like this
{"mat": [ [ 0, 1, 2], [3, 4, 5], [6, 7, 8] ]
}

Here are the templates to process it:
group matrix;

main() ::= <<
  $table(t=mat)$
>>
table(t) ::= <<
  <table>
    $t:{<tr>
      $row(it)$
      </tr>}$
  </table>
>>
row(r) ::= <<
 $r:{<td>$it$</td>}$
>> 

---- Original message ----
>Date: Wed, 10 Oct 2007 16:58:02 -0700
>From: StoreAdmin <webmaster at storeadmin.com>  
>Subject: [stringtemplate-interest] How to fill a <table> grid wise?  
>To: stringtemplate-interest at antlr.org
>
>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


More information about the stringtemplate-interest mailing list