Very short example of a Page with xml template and a table which is used to render some data (with stan).
Thanks to Brend for sharing this with me (he also said that there is probably some way to do it without stan, but I quite like this as it is easy to use):
First up the python code(I'll sort out the indent issues later but for now just add the appropriate indent for python code - if you don't know what I mean you should probably read a python howto first):from nevow import rendfrom nevow import loadersfrom nevow import tags as Tclass SiteRoot(rend.Page): addSlash = True docFactory = loaders.xmlfile('templates/page.xml') def data_title(self, ctx, data): return u'Blechlager Verwaltung' def render_testTable(self, ctx, data): rows = [[11,12],[21,22],[31,32]] tags = [] for (a, b) in rows: tags.append( T.tr [ T.td [ a ], T.td [ b ] ]) ctx.tag = tags return ctx.tag
And now the xhtml template for it:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" xmlns:nevow="http://nevow.com/ns/nevow/0.1"><head> <title nevow:data="title" nevow:render="string" /></head><body> <h1 nevow:data="title" nevow:render="string" /> <table> <tr> <th>One</th><th>Two</th> </tr> <span nevow:render="testTable" /> </table></body></html>
Comments
There are currently no comments
New Comment