Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Add a Template.render_blocks method #120

wants to merge 1 commit into from

2 participants


I wrote a method to render each block of a template, and return them all in a dict. Would you consider merging this in if it had proper tests/docs?


Closing this for the time being since I have not processed it in a long time. Do you still think it's useful?

@mitsuhiko mitsuhiko closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 25, 2012
  1. @johnsoft
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 0 deletions.
  1. +16 −0 jinja2/
16 jinja2/
@@ -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
Something went wrong with that request. Please try again.