How to generate an HTML table in Sitebricks?

262 Views Asked by At

Using Sitebricks, I want to generate a table where one object backs each <td> in a table. The only examples I've seen have one object back an entire <tr> - so the HTML is consistent across each row. I would like to be able to wrap N entries in <tr>.

I don't want to have to have my page object in Sitebricks be aware of the layout of the page (and so have to add indices or structure the items as a List<List<Something>>).

Any ideas?

Edit: This is, of course, not limited to Sitebricks, but is a general question about separation of model from view using web templating systems.

2

There are 2 best solutions below

0
On

Seems like you can put the @Repeat in front of anything. I don't think it cares about whether it's a row in a table or a column.

https://github.com/dhanji/sitebricks/blob/master/sitebricks-acceptance-tests/src/main/resources/Repeat.html

If you're trying to keep track of the index so you can emit special stuff every nth row, I don't know.

0
On

Yep, you can add @Repeat on any tag. The implicit variables index and last are defined for you to do your own logic inside the repeat. You could, for example, add a CSS class if index % 2 == 0 to color even rows differently.

Here is a testcase showing how this works for non-table tags (the tags really don't matter):

https://github.com/dhanji/sitebricks/blob/master/sitebricks-acceptance-tests/src/main/resources/Repeat.html