Wichert, thank you so much for your explicit example! I'll try that out this week. =)
Iain On 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? > > In config/environment.py: > > from genshi.template import TemplateLoader as GenshiTemplateLoader > > 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. > > Wichert. > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
