Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added the Template.render_blocks method

  • Loading branch information...
commit 6a19fb398745d91a387bf01efd2f3ecbee85ff62 1 parent a21f2ed
@johnsoft authored
Showing with 16 additions and 0 deletions.
  1. +16 −0 jinja2/environment.py
View
16 jinja2/environment.py
@@ -893,6 +893,22 @@ def render(self, *args, **kwargs):
exc_info = sys.exc_info()
return self.environment.handle_exception(exc_info, True)
+ def render_blocks(self, *args, **kwargs):
+ """
+ This method renders each block of the template, and returns a dict where
+ the keys are the block names, and the values are the corresponding
+ rendered content.
+ """
+ context = self.new_context(dict(*args, **kwargs))
+ try:
+ blocks = {}
+ for name, func in self.blocks.iteritems():
+ blocks[name] = concat(func(context))
+ return blocks
+ except Exception:
+ exc_info = sys.exc_info()
+ return self.environment.handle_exception(exc_info, True)
+
def stream(self, *args, **kwargs):
"""Works exactly like :meth:`generate` but returns a
:class:`TemplateStream`.
Please sign in to comment.
Something went wrong with that request. Please try again.