Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Template.render_blocks method #120

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions jinja2/environment.py
Expand Up @@ -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`.
Expand Down