[Twisted-web] Re: new nevow know-how needs...;-)

James Y Knight twisted-web@twistedmatrix.com
Fri, 5 Mar 2004 11:14:38 -0500


On Mar 5, 2004, at 6:15 AM, Alex Martelli wrote:
> So, won't every
> HTML construct coming from a template of some form such as:
>
> <span nevow:data="bar">
>     etc, etc
> </span>
>
> end up "compiled" into a "span(data=directive('bar'))[etc, etc]" 
> anyway,
> leading me right back into subtle issues of "WHERE is this 'bar'
> going to be looked up, depending on phase of the moon etc"...?  Or are
> there two different ways I should code that '<span nevow:data="bar">' 
> in
> the on-disk template depending on whether I mean one thing or the 
> other?

Welll, it doesn't depend on the phase of the moon. directives always 
get looked up on the first data it finds above it in the tree. I'm not 
sure exactly what your question is, but, is it the lack of being able 
to go back up the tree? e.g.:
class MyPage:
   def data_foo(context, data):
     return {'bar':2, 'baz':3}
   def data_other(context, data):
     return 1
   docFactory = xmlstr("""
   <html>
     <span data="foo">
       <span data="bar" render="string">This works fine.</span>
       <span data="other" render="string">This won't work because 
'other' isn't a key in {'bar':2, 'baz':3}.</span>
     </span>
   </html>""")


> Anyway, if I understand correctly, I'll now get this "new behavior" 
> with
> just a cvs up on the (stand-alone) Nevow CVS, which I intend to do at
> once, so I can experiment.

Yep.

> But, if I can get some explanation of how
> things are designed to work, this might help.  Perhaps as small a 
> change
> as "if the current IData remembrance is not adaptable to IContainer 
> [and
> perhaps also if it is, but its .get raises?], just back off to 
> 'external'
> IData remembrances until a satisfactory one is found" would be 
> sufficient
> for my purposes, and -- if you can confirm there's no other solution 
> that
> better matches the current intent of the code -- I could experiment 
> with
> that kind of approach.

I dont think that's the right solution. Too magical. And, what if your 
data *is* a container but you still want to get to something outside 
it? One idea that's been proposed and that makes a lot of sense to me 
is a "../" syntax, so you could say data="../other" or "/other" in the 
example above. It just hasn't been implemented yet.

James