Here some small code - snippets where some form of data gets passed to a page / element. This could of course be changed to get more data or not a dict/axiom db but I prefer it this way (Pretty much every axiom/nevow app will need something like this afaik):# -*- coding: utf8 -*-from nevow.rend import Pagefrom nevow.page import Element, rendererfrom nevow import loadersfrom nevow import tags as Tclass PageWithDB(Page): """ Own Page class to save myself passing the db object to every sub-page """ def __init__(self, db, original = None, docFactory = None): self.db = None if not db: raise ValueError("No Database given") self.db = db Page.__init__(self, original, docFactory)class ElementWithData(Element): """ Element with Data """ def __init__(self, data, docFactory = None): self.data = None if data == None: raise ValueError("No Data") self.data = data Element.__init__(self, docFactory)class ContainerPage(PageWithDB): """ Container Page which just has title and content renderer and loads only skeleton page. To be used with Elements The render_title and render_content methods should be overridden """ addSlash = True docFactory = loaders.xmlfile(u'templates/pageskel.xml') def render_title(self, ctx, data): return u'TITLE RENDER' def render_content(self, ctx, data): return u'CONTENT'
The ContainerPage class is just a small class where I render the title as actual and on top of the page. The template is of course flexible. I use this to override render_content and then return a list of Elements, stan, ..
Here is the template I use (it is very basic as what I write at the moement is a very simple webapp):<!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="de" xml:lang="de" xmlns:nevow="http://nevow.com/ns/nevow/0.1"><head> <title><span nevow:render="title" /></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body> <h1><span nevow:render="title" /></h1> <span nevow:render="content" /></body></html>
Comments
There are currently no comments
New Comment