[Twisted-web] fragments with child lookup

Markus Schiltknecht markus at bluegap.ch
Mon Sep 25 05:51:41 CDT 2006

Valentino Volonghi aka Dialtone wrote:
> On Mon, 25 Sep 2006 12:01:12 +0200, Markus Schiltknecht 
> <markus at bluegap.ch> wrote:
>> Okay, thanks. But now... how can I remove the hard-coded 'level' 
>> number? I would like to write 'components' or Fragments which don't 
>> care on what level they are used.
> Use -1 as an index. It will take the last segment each time.

<div nevow:render="content_-1">  probably won't work...

To be able to do it that way, I would have to stuff the dictionaries 
with fragments into an array with levels, i.e.

fragments_1 = {
     '_default': loaders.xmlfile('templates/default.html'),
     'kontakt': loaders.stan(...),

fragments_2 = {
     '_default': ..
     'info': ...

levels = [fragments_1, fragments_2]

But even then, I cannot write a common renderer, because how does it 
tell which fragment to serve, i.e. at what level it currently is.

def render_content(self, ctx, data):
         fragment_name = inevow.ICurrentSegments(ctx)[???]

I tried using the context here and store something in there, i.e. a 
counter which gets incremented every time render_content is called. I'm 
trying stuff like that.

Sill I'm still surprised, nevow does not provide that functionality.

>> Another thing that bugs me is the duplicate definition of the 
>> children: I have to set the child_XY attribute as well as the fragment 
>> dictionary. But that can easily be avoided, I think.
> Build those dictionary dynamically at startup time.

Yep. Easy enough.

 >> That does the URL-space-embedding of the pastebin into another page.
 >> But not the design wise embedding.
 > That does what the pastebin can do at most. If it's not designed to be
 > embedded than you cannot embed it, simple.

I think another way to look at my problem is: how do I code a pastebin 
that _can_ be embedded like that? A pastebin which can be a fragment of 
another page.



More information about the Twisted-web mailing list