In Sat, 2009-09-19 at 09:40 +0200, Wichert Akkerman wrote:
> On 2009-9-16 21:06, Iain Duncan wrote:
> >
> > Hi folks, I have not built enough pylons to be know how to switch
> > templating languages beyond mako and genshi, but I'm interested in using
> > Chameleon. Has anyone got any examples up of what one needs to do to use
> > Chameleon?

Thanks Wichert, I've hit some problems here, and muddled along a bit, if
you ( or someone ) can check this that would be great.

> 
> In config/environment.py:
> 
> from genshi.template import TemplateLoader as GenshiTemplateLoader

I assume I'm also supposed to add??

from chameleon.zpt.loader import TemplateLoader


> 
> def load_environment(global_conf, app_conf):
>      ...
>      ...
> 
>      # Create the chameleon TemplateLoader
>      config['pylons.app_globals'].pt_loader = TemplateLoader(
>          paths['templates'], auto_reload=True)
> 
> Add a new file in lib (mine is called lib/pt.py):
> 
> from pylons.templating import pylons_globals
> from pylons.templating import cached_template
> 
> 
> def render_pt(template_name, cache_key=None, cache_type=None,
>                    cache_expire=None):
>      """Render a page template with z3c.pt."""
> 
>      def render_template():
>          globs = pylons_globals()
>          template = globs["app_globals"].pt_loader.load(template_name)
>          return template(**globs)
> 
>      return cached_template(template_name, render_template, 
> cache_key=cache_key,
>              cache_type=cache_type, cache_expire=cache_expire)
> 
> 
> def render_text(template_name, cache_key=None, cache_type=None,
>                    cache_expire=None):
>      """Render a text template with z3c.pt."""
> 
>      def render_template():
>          globs = pylons_globals()
>          template = globs["app_globals"].pt_loader.load(template_name, 
> format="text")
>          return template(**globs)
> 
>      return cached_template(template_name, render_template, 
> cache_key=cache_key,
>              cache_type=cache_type, cache_expire=cache_expire)
> 
> 
> you can then use render_pt to render html/xml templates, and render_text 
> to render text templates, exactly like you use other templating languages.

I copied the above in, and imported render_pt from lib/pt.py, but when I
try to render a template like so:

(in a controller)
  def zpt(self):
        "test of using zpt templates"
        return render_pt("mytemplate.pt")

I get the following traceback, any help much appreciated.

File '/home/ymh/pylons_full/pylons_full/controllers/peek.py', line 50 in
zpt
  
File '/home/ymh/pylons_full/pylons_full/lib/pt.py', line 15 in render_pt
  cache_key=cache_key, cache_type=cache_type, cache_expire=cache_expire)
File
'/home/ymh/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/templating.py',
 line 249 in cached_template
  return render_func()
File '/home/ymh/pylons_full/pylons_full/lib/pt.py', line 11 in
render_template
  template = globs["app_globals"].pt_loader.load(template_name)
File
'/home/ymh/lib/python2.5/site-packages/chameleon.zpt-1.0.0-py2.5.egg/chameleon/zpt/loader.py',
 line 11 in load
  template.PageTemplateFile)
File
'/home/ymh/lib/python2.5/site-packages/chameleon.core-1.0.0-py2.5.egg/chameleon/core/loader.py',
 line 8 in load
  self.registry[args] = template = func(self, *args)
File
'/home/ymh/lib/python2.5/site-packages/chameleon.core-1.0.0-py2.5.egg/chameleon/core/loader.py',
 line 39 in load
  path, self.parser, auto_reload=self.auto_reload)
TypeError: __init__() takes exactly 2 non-keyword arguments (3 given)



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to