Monday, December 1, 2008

Issues with Kid templating

Was working on my little Turbogears app I'm building and ran into some issues with the Kid template system that's default with turbogears 1.0.

Now I've wasted several hours just messing around with master and layout files. I can build my own master file and have it work quite well, but no one wants to see my websites so I grabbed a template off OSWD and it was even in strict xhtml.

First, I try the master approach. This is to me a pretty noisy process (have to specify match parameters in html, head, and what i want to be the content area, i learned through trial and error this does not seem to be optional) but at least it looks like a complete xhtml file to a web designer.

Now the specific pages just need a py:extends="'sitemaster'" attribute in the html tag and blows up with an odd error (
Template file "'sitemaster.kid'" not found
while processing layout="'sitemaster.kid'"

I dive into the kid language specification and find the py:layout="'sitemaster'" option. this looks much better. far less noise and at least somewhat closer to what you'd find in NVelocity or Brail.
However in the end once I've made the same changes, done a test case that works with some hand thrown together html. When trying to load up my 3rd party template it blows up with same odd error.

Long story short, I narrowed enough down to find there is something in an WC3 xhtml strict compliant doc that throws the kid parser for a loop. I can delete all the html in the body and it works.

I believe the way kid ends up approaching things is ultimately to blame here, and I'd have to change the template output to strict xhtml or something to get this all to work..but ultimately I shouldn't have to think about this at all.

It is my belief that view engines should stay out of the way of the html entirely, they shouldnt barf on it, and if they do they should tell you what element is causing you the problem, or where the parser gives up at the horrible mess you've sent it.

I get that Kid is trying really hard to make a designer friendly view engine, but in this instance if I were working with a designer and we got this error when he made an html change..and he actually did it 3 days ago, and he did a bunch more changes since...we'd be struggling for hours to figure out what was the offending piece of html he added.

Now I'm sure experienced users of Kid would chastise me, and that I'm supposed to learn all the ins and outs and then it'll all be worth it (it may very well be, but I'm not convinced yet).

I had a look at genshi and it looks like the same model but better in some ways (extension is .html..this alone makes it worthwhile for dealing with skiddish designers). Maybe it'll tell me where this html blows up...regardless I'll say it again..view engines should not care what html I throw it.

No comments: