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.

   Example:

   <span nevow:pattern="foo">
	 I'm very repetititive.
   </span>
   <ul>
	 <li nevow:render="pattern foo">
	   this text will get removed when rendering
	 </li>
	 <li nevow:render="pattern foo"/>
   </ul>
   """
   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.

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