[Twisted-web] Nevow and template like files

Nuutti Kotivuori naked at iki.fi
Tue Sep 5 10:13:37 CDT 2006


Hi,

I'm considering the best ways to write a Nevow site that would meet my
needs. I know I can come up with several solutions to my problems
myself, but I am pondering on the best way to achieve them. I will
first describe my needs and then give an idea how I was thinking of
achieving it.

I will have three classes of xhtml files, or templates, that are used
in different parts of the code.

First are layout pages. These will provide the general
layout and functionality for a set of pages that will make up a
section of the site. These pages will contain the actual
html/head/body tags and such.

Second are the content pages. These pages will fit in a certain layout
and provide the actual page content to it. There will be static pages,
dynamic status pages and pages with web forms. The layout pages need
to be able to dig sections out of the content pages to fill in to the
layout; for example additional css/javascript to go into head, sidebar
items, actual content.

Third are so called snippet pages. These will contain a large number
of text snippets (with markup) that are re-used on many content
pages. These snippets need to be easily includable from the content
pages. Some of the snippets are used as is, where as some of the
snippets need to be parameterised - the calling code needs to be able
to fill in some things easily.

And that's it. The way I was going to go about it was rather
straightforward.

Layout pages would be simply Pages, with the layout file as
docFactory and a few macros defined.

Content pages would inherit from layout pages, and specify the content
file somehow (contentDocFactory?). The macros from layout pages would
just directly use patterns from the content pages to fill in stuff.

Snippet pages are a bit troublesome. I was thinking of making a
Fragment that would have the docFactory for such a page. Then that
fragment would be instantiated where ever some snippet was to be used,
and a simple method would be called on it. This method would get the
document, get a pattern from it, call fillSlots a couple times and
return it. I could make a macro which does this based on the arguments
it receives.

But it's all a bit in the air.

Things I'd like to avoid or achieve. I wouldn't want the actual xhtml
templates to be read many times in the life of the program - it may
even be a problem with macros if a page is read once per every pattern
used from it - so I'd like for them to be read just once. I'd like a
way to have some patterns be optional, so I could provide a default
thing to do in case they are not found. And I'd like the lookup of the
snippet patterns be somehow pre-done, so that every inclusion of a
snippet wouldn't have go to through 1000 DOM nodes to find the right
part.

So, any suggestions on how to actually go about making this happen?

-- Naked







More information about the Twisted-web mailing list