Render_if: Conditional Parts in Nevow Templates

http://eagain.net/blog/2005/12/17/nevow_render_if.html

 

def render_if(self, ctx, data): r=ctx.tag.allPatterns(str(bool(data))) return ctx.tag.clear()[r] 

<nevow:invisible nevow:render="if" nevow:data="items"> <ul nevow:pattern="True" nevow:render="sequence"> <li nevow:pattern="header">The items are a-coming!</li> <li nevow:pattern="item">(the items will be here)</li> </ul> </nevow:invisible> 

def render_ifparam(self, name): tester = getattr(self, 'tester_%s' % name, None) if tester is None: callable = lambda context, data: context.tag[ "The tester named '%s' was not found in %r." % (name, self)] return callable def f(ctx, data): r=ctx.tag.allPatterns(str(bool(tester(data)))) return ctx.tag.clear()[r] return f 

你可能感兴趣的:(Render_if: Conditional Parts in Nevow Templates)