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 TG2

TurboGears 2.0

May 27, 2009 Install the 2.0 final release from our custom package repository. Many people are already using it in production. If you're upgrading from an earlier alpha here's the changelog.

Download now button

Download TG2.1 beta

TurboGears 2.1b1

January 25, 2009 Install latest 2.1 beta release from our custom package repository. If you're upgrading from an earlier beta here's the changelog.

Download now button

Download TG 1.1

TurboGears 1.1

Oct 4, 2009 1.1 is the first release of the 1.1 branch. It features SQLAlchemy and Genshi as the defaults for quickstarted applications. TurboGears 1.1 has been in beta testing for a long time but deployed in real, high demanding production environments already for more than a year. See the changelog for everything else that's new!

Download now button
TG 1.1 Documentation

Download TG 1.0.9

TurboGears 1.0.9

Oct 16, 2009 1.0.9 is the latest maintenance release from the 1.0 branch. See the changelog for the list of changes.

Download now button
TG 1.0 Documentation

Community

Advertisement

Rapid Web Applications with TurboGea...

Mark Ramm, Kevin D...

  Buy New $29.69

Privacy Information

Hosting Options

TurboGears can be hosted in many places, but we've got some of the best choices picked out. Super simple TurboGears use from WebFaction starting at $7.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: Jun 25, 2007
Comment on this page