self.render('templates/apps/home.html');I'm currently handling this with:
or
self.render('templates/apps/home.html', message='Danger, Will Robinson!');
{% try %}But I think there should be a more straight forward way to handle this such as finding the right object to check has_key() against.
% if message %}
<p class="error">{{ message }}</p>
{% end %}
{% except %}
{% end %}
You also could this in the template:
{% if 'message' in globals() and message %}
<stuff>
{% end %}
def render_string(self, template, **kwargs):
return super(BaseHandler, self).render_string(
template, helpers=helpers, **kwargs)
On Dec 22, 3:45 pm, "David P. Novakovic" <davidnovako...@gmail.com>
wrote:
class contextObject():
data = {}
def __getattr__(self, name):
return self.data[name]
def __setattr__(self, name, val):
self.data[name] = val
def __setitem__(self,name,val):
self.data[name] = val
def __getitem__(self, name):
return self.data[name]
def get(self):
return self.data
tplContext = contextObject()
class MyController(request.RequestHandler):
def _render(self, template):
"""
Render function for Jinja2
"""
env = self.application.env
self.set_header("Content-Type", "text/html; charset=UTF-8")
tpl = env.get_template(template)
self.write(tpl.render(**tplContext.get()))
def index(self):
self.set_header("Content-Type", "text/html; charset=UTF-8")
tplContext.type = '13a'
tplContext['test'] = 'test'
self._render('test.html')
self.finish()