2
By VladDrac@irc.freenode.net/#turbogears
3
+ Some small modifications
6
from zope.pagetemplate import pagetemplatefile
11
def __init__(self, base, options):
13
self.options = options
15
def __getitem__(self, name):
16
tpl = PageTemplate(os.path.join(self.base, name))
17
tpl.add_context(self.options)
20
class PageTemplate(pagetemplatefile.PageTemplateFile):
21
def __init__(self, name):
22
base = os.path.dirname(sys._getframe(1).f_globals["__file__"])
23
self.extra_context = {}
25
self.fullpath = os.path.join(base, self.name)
26
self.base = os.path.dirname(self.fullpath)
27
pagetemplatefile.PageTemplateFile.__init__(self, self.fullpath)
29
def render(self, extra_dict=None):
31
context = self.pt_getContext()
32
context.update(extra_dict)
33
return self.pt_render(context)
35
def add_context(self, d):
36
self.extra_context.update(d)
38
def pt_getContext(self, args=(), options={}, **ignored):
39
rval = pagetemplatefile.PageTemplateFile.pt_getContext(self, args, options, **ignored)
41
rval.update(self.extra_context)
42
rval.update({'here':Here(self.base, options), 'template':self})