L. Daniel Burr ha scritto:
[...]
I will migrate to twisted web2 + django template, where I can write:
<table> <caption>RandomTable</caption> <thead> <tr> {% for i in header %} <th>{{ i }}</li> {% endfor %} </tr> </thead> <tbody> {% for i in table %} <tr> {% for j in i %} <td>{{ j }}</td> {% endfor %} </tr> {% endfor %} </tbody> </table>
I will note that this is most definitely *not* XHTML, so your statement "...want to write XHTML code as much as possible." doesn't make sense. The nevow template would probably pass XHTML validation, but this Django template surely won't, so I don't understand your point.
The point is that in the template it should be "visible" the XHTML that will result. As an example, this code: <ul nevow:pattern="sums-container"> <nevow:slot name="elements" /> </ul> <li nevow:pattern="sums-element"> <nevow:slot name="date" /> <nevow:slot name="value" /> </li> <ul nevow:pattern="methods-container"> <nevow:slot name="elements" /> </ul> <li nevow:pattern="methods-element"> <nevow:slot name="method" /> <nevow:slot name="value" /> </li> <div> Wallclock duration totals (seconds) <nevow:invisible nevow:render="totalWallClock" /> </div> give me no clue on how the renderized page will look.
Moreover, you've embedded iteration logic in the Django template, so if some idea of "XHTML purity" is driving you, the the Django approach, while faster, is less pure.
Nevow has a better solution: the sequence renderer. But it will go away.
[...]
The most important thing is to stop thinking in terms of data types (render="sequence", render="string"), and just write render methods that deal with app-level concepts (headers, rows).
An important point to make here, is that the code I provided above is based on the same code used to implement the "sequence" directive, so there is really nothing magical going on.
Ok, but what about reusability? Now for every table (in theory) I have to reimplement the sequence logic. Well, I'm sure that it is possible to write generic/reusable code for rendering tables.
Hope this helps,
Yes, thanks. I will try to use slots instead of data. P.S. How tested/stable is the new(?) page module? Regards Manlio Perillo