render_pattern: Repeat patterns easily in Nevow templates

After render_fragment, dialtone mentioned render_pattern, that would get one or many patterns from the page and put them in the current tag. Well, that's easy to write:

def render_pattern(self, name):
   Find and render a pattern.


   <span nevow:pattern="foo">
	 I'm very repetititive.
	 <li nevow:render="pattern foo">
	   this text will get removed when rendering
	 <li nevow:render="pattern foo"/>
   def f(ctx, data):
	   doc = self.docFactory.load(ctx)
   patterns = inevow.IQ(doc).allPatterns(name)
   return ctx.tag.clear()[patterns]
   return f

Updated to adapt doc to inevow.IQ before calling allPatterns.

  • nevow
  • twisted
  • python
  • programming
2005-12-27T11:48+02:00, originally published 2005-12-21T19:18+02:00