Tuesday, December 2, 2008

Mako Templates

Ok so tired of the goofy stuff with Kid even though I did find out a way to debug templates but I was still upset enough that I wanted to go away from an XML based template engine entirely.

Enter Mako. Mako is newish but the preferred engine of Pylons and it works on Turbogears as well. Instead of being xml based it's a run of the mill view engine using python as it's scripting language. This struck me as the easiest and most straight forward for my skill set(especially since I use the pythonic Brail in Monorail).

Turbogears and Mako integration take some hunting. I had to resort to just giving it a stab how I wanted it to work, googling my errors, and then bit by bit piecing together the sections of configuration i needed.

Finally I groked the concept thanks to Wesley Chun the author of Core Python Programming who'd run into a similar conundrum (at least it makes me feel less stupid) .

Key excerpt here:

2. another problem that people have is that in your controller, your @expose decorator call tends to have more of a "full-path" to the template when porting from Kid, i.e.,

@expose(template="tghello.templates.hello") def hello(self): :

when switching to Mako, because of your mako.directories list, you no longer have to give the entire path, meaning that the failures are happening because it's trying to find that full name as a template file name, which isn't going to work.


Finally, played with this briefly feel much more at home with this templating style.

No comments: