title: Help with custom Jinja2 Extension
body: <p>I've struggled to get this Jinja2 custom extension to work -- the docs weren't kidding when they said writing one was not for "civilians" -- and finally managed to arrive at this working code:</p>
  
  <pre><code>class WrapperExtension(Extension):
  
      tags = set(['wrap'])
  
      def parse(self, parser):
          lineno = parser.stream.next().lineno
          args = [parser.parse_expression()]
          args.append(nodes.Const(args[0].name))
          return nodes.CallBlock(
              self.call_method('_render', args),
              [], [], []).set_lineno(lineno)
  
      def _render(self, value, name, *args, **kwargs):
          if some_condition():
              return '&lt;wrapper id="%s"&gt;%s&lt;/wrapper&gt;' % (name, value)
          return value
  </code></pre>
  
  <p>As I said, this is now working. What I'm unsure about is why I need to return <code>nodes.CallBlock</code> in <code>parse()</code>, rather than <code>self.call_method()</code> (which returns a <code>nodes.Call</code> object). If anyone has any insight -- or can point me to a tutorial on writing extensions -- please do let me know.</p>