* I want the template to be defined in the common code base.
* I want the application to be able to extend or modify the template if
applicable (like modifying a widget)
* I want the template to be able to extend an application specific site
master or layout template.
I noticed a thread a while back (http://tinyurl.com/yb32ta) that talked
about loading templates from a dynamic source. There were some issues
and the proposed solution required adding a KID plugin to load the
template.
Would this be easier if I switch to Genshi? I'm not opposed to
upgrading anyway since that is the future.
Ideally I'd like to have something like this in my common controller
method:
class CommonController:
def __init__(self,mastertemplatename):
self.mastertemplatename=mastertemplatename
@expose()
def somecommontask(self,**kw):
template=pkg_resources.resource_string(__name__,'commontemplate.txt')
return
dict(tg_template=template,mastertemplatename=self.mastertemplatename)
Thoughts?
Thanks for any input.
-Dennis
I posted something a little while back about adding themes to your
site. You can find it here:
http://groups.google.com/group/turbogears/msg/45da05797acb85dc
The concept seems similar to what you are trying to do, although your
usage of it would be more complicated.
hth,
-Adam
Yes, it is easier with Genshi thanks to it's support for XInclude
(http://tinyurl.com/ya4j2k).
You can even use "py" directives to generate the include tags :)
Alberto
Yes, I had figured that out and was about to post my results. The
XInclude header does indeed make life easy on the template side. The
only thing I had to worry about is that turbogears doesn't seem to have
a way to specify more template paths. I did that manually.
Here is a simple controller that I can mount from any application.
class CommonController:
"""
Including site simply has to let controller know the path to
the site templates
and the name of the master template file.
"""
def __init__(self,template_dir,master_path):
self.t_dir=resource_filename(__name__,'templates')
self.t_loader=TemplateLoader([self.t_dir,template_dir])
self.master_path=master_path
@expose()
def login(self,**kw):
t=self.t_loader.load('login.html') # this template is in the common
template dir
return t.generate(master_path=self.master_path).render()
Thoughts?
Can you think of a better way to accomplish this?
-Dennis