Skip to content
This repository has been archived by the owner on Apr 16, 2019. It is now read-only.

Commit

Permalink
Templates now have a rendering context "bf.context"
Browse files Browse the repository at this point in the history
This context is provided during the entire render process of a single template and is accessible from inheritted or included templates. This is easier than having to pass values around between parent/children templates

One value is added by default, the template name as "bf.context.template_name"
  • Loading branch information
EnigmaCurry committed Mar 28, 2010
1 parent ae38262 commit 2437b09
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions blogofile/writer.py
Expand Up @@ -149,12 +149,18 @@ def __run_controllers(self):
logger.debug("Controller %s has no run() function, skipping it." % py_file)

def template_render(self, template, attrs={}):
"""Render a template"""
#Create a context object that is fresh for each template render
self.bf.context = cache.Cache(**attrs)
#Provide the name of the template we are rendering:
self.bf.context.template_name = template.uri
attrs['bf'] = self.bf
try:
return template.render(**attrs)
except: #pragma: no cover
logger.error("Error rendering template")
print(mako_exceptions.text_error_template().render())
del self.bf.context

def materialize_template(self, template_name, location, attrs={}):
"""Render a named template with attrs to a location in the _site dir"""
Expand Down

0 comments on commit 2437b09

Please sign in to comment.