Kid: Designer and programmer friendly templates

Your designer will love you for using Kid. As far as they're concerned, they're just giving you XHTML that you put some extra stuff into. The designs they put together can even have sample data that hangs around and gets replaced by the real data when the time comes.

OK, sure. Not everyone works with a designer. (I've seen lots of pages that prove that. I've made lots of pages that prove that!) That's OK... Kid is friendly for programmers, too.

It's just Python

If you were generating your output in straight Python, you could do something like this:

In a Kid template, you just do it like this:

The expressions in Kid's "for" and "if" commands are standard Python! Note also that the example above is the "designer-friendly" form that would have nice sample data to show in an editor or browser. If you want, you can use the more succinct "${person.name}" instead of having the extra <span>.

Applying consistent templating throughout

Sure, we all use CSS these days to apply consistent style throughout our apps, but you still need a mechanism for consistent headers and footers. Kid provides a couple of useful ways to do this.

Template Inheritance

You can create a header in a "template function" in a master template that looks something like this:

Then, your individual templates will "extend" your master template and call the function to insert the header:

Matching

Kid has a great feature that gives you some of XSLT's power without XSLT's syntax: the "match" command. As in the previous example, you'd have your template extend a master template. However, rather than explicitly calling a header function, the master template will add the header through matching.

By putting the code above in your master template, all you have to do is extend the master template for each separate page you make. The headers (and footers, if desired) will automatically be added. Plus, other changes could be made to the final document, if you need to!

I really want to write code in my template!

OK, if you must. Just don't tell anyone... Kid lets you do what you need to do. You can incorporate some Python directly into your template by enclosing it in <?python?>. Since this is a processing instruction, your template remains valid XHTML.

Kid won't give you garbage

Many template systems make it possible to leave tags hanging or mismatched. With Kid, your template must be valid XML, so you're guaranteed to not have mismatched tags. Many browsers don't properly support XHTML. When the time comes to deliver your content to a web browser, TurboGears will transparently output HTML based on your XHTML template and your data.

Return to About TurboGears.

Download

TurboGears 1.0b1

September 7, 2006

Features: Widgets, ModelDesigner, Identity framework, FastData, and much more

Download now button Upgrade instructions button

Download development version from SVN

Get involved

Order the DVD and more!

The TurboGears Ultimate DVD is now shipping! More than 5 hours of video!
We also have the marble rolling mini-framework you've been looking for.

Hosting Options

TurboGears can be hosted in many places, but we've got 4 of the best choices picked out. Super simple TurboGears use from WebFaction starting at $11.50 a month or, if you need more control, dedicated servers from ServerPronto starting at just $29.95 a month. Check it out
last updated: Aug 09, 2006
Comment on this page