[Twisted-web] Re: Trouble with templates
Jason Mobarak
jason at mobarak.name
Fri Jul 2 13:48:11 MDT 2004
"""
This is the solution fzZzy provided.
"""
from twisted.application import service
from twisted.application import internet
from nevow import appserver, loaders, rend, tags, inevow
from formless import annotate, webform, iformless
xml0 = loaders.xmlstr("""<?xml version="1.0"?>
<html xmlns:n="http://nevow.com/ns/nevow/0.1">
<body>
<div n:render="sequence" n:data="foo">
<p n:render="sequence" n:pattern="item">
<span n:pattern="item" n:render="string" />
<span n:pattern="item" n:render="string" />
<div n:pattern="footer" n:render="bar">
<n:slot name="bar" />
</div>
</p>
</div>
</body>
</html>
""")
xml1 = loaders.xmlstr("""<?xml version="1.0"?>
<p xmlns:n="http://nevow.com/ns/nevow/0.1" n:data="baz" n:render="string" />
""")
class FooFragment(rend.Fragment):
docFactory = xml1
def data_baz(self, ctx, d):
return "baz"
class FooPage (rend.Page):
docFactory = xml0
def data_foo (self, ctx, d):
return [['foo ', ' bar'], ['oof ', ' rab']]
def render_bar (self, ctx, d):
ctx.fillSlots('bar', FooFragment())
return ctx.tag
application = service.Application("MinimalExample")
server = internet.TCPServer(8080, appserver.NevowSite(FooPage()))
server.setServiceParent(application)
Jason Mobarak wrote:
> """
> I'm having trouble with templates and slots... this example code is
> producing a traceback, am I doing something wrong?
> """
>
> from twisted.application import service
> from twisted.application import internet
>
> from nevow import appserver, loaders, rend, tags, inevow
> from formless import annotate, webform, iformless
>
> xml0 = loaders.xmlstr("""<?xml version="1.0"?>
> <html xmlns:n="http://nevow.com/ns/nevow/0.1">
> <body>
> <div n:render="sequence" n:data="foo">
> <p n:render="sequence" n:pattern="item">
> <span n:pattern="item" n:render="string" />
> <span n:pattern="item" n:render="string" />
> <div n:pattern="footer" n:render="bar">
> <n:slot name="bar" />
> </div>
> </p>
> </div>
> </body>
> </html>
> """)
>
> xml1 = loaders.xmlstr("""<?xml version="1.0"?>
> <p xmlns:n="http://nevow.com/ns/nevow/0.1" n:data="baz" n:render="string" />
> """)
>
>
> class FooPage (rend.Page):
>
> docFactory = xml0
>
> def data_foo (self, ctx, d):
>
> return [['foo ', ' bar'], ['oof ', ' rab']]
>
> def render_bar (self, ctx, d):
>
> ctx.fillSlots('bar', xml1)
> return ctx.tag
>
> def data_baz (self, ctx, d):
>
> return "baz"
>
>
> application = service.Application("MinimalExample")
> server = internet.TCPServer(8080, appserver.NevowSite(FooPage()))
> server.setServiceParent(application)
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Twisted-web mailing list
> Twisted-web at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
-------------- next part --------------
# -*- python -*-
from twisted.application import service
from twisted.application import internet
from nevow import appserver, loaders, rend, tags, inevow
from formless import annotate, webform, iformless
xml0 = loaders.xmlstr("""<?xml version="1.0"?>
<html xmlns:n="http://nevow.com/ns/nevow/0.1">
<body>
<div n:render="sequence" n:data="foo">
<p n:render="sequence" n:pattern="item">
<span n:pattern="item" n:render="string" />
<span n:pattern="item" n:render="string" />
<div n:pattern="footer" n:render="bar">
<n:slot name="bar" />
</div>
</p>
</div>
</body>
</html>
""")
xml1 = loaders.xmlstr("""<?xml version="1.0"?>
<p xmlns:n="http://nevow.com/ns/nevow/0.1" n:data="baz" n:render="string" />
""")
class FooFragment(rend.Fragment):
docFactory = xml1
def data_baz(self, ctx, d):
return "baz"
class FooPage (rend.Page):
docFactory = xml0
def data_foo (self, ctx, d):
return [['foo ', ' bar'], ['oof ', ' rab']]
def render_bar (self, ctx, d):
ctx.fillSlots('bar', FooFragment())
return ctx.tag
application = service.Application("MinimalExample")
server = internet.TCPServer(8080, appserver.NevowSite(FooPage()))
server.setServiceParent(application)
More information about the Twisted-web
mailing list