From Kid to Genshi – Changing template language

Genshi (formerly Markup) is a library that provides an integrated set of components for parsing, generating, and processing HTML, XML or other textual content for output generation on the web.

Replacing Kid with Genshi XML Template Language makes a lot of sense:

  • Better performance
  • Easier to debug
  • Uses standards like XPath and XInclude
  • TurboGears 1.1 will by default use Genshi as its template engine.

XInclude alone is a reason to use Genshi. It is an inclusion mechanism to facilitate modularity, and a recommendation by W3C.

Migrating to Genshi is very simple. Most things will work without change.

Below is an example of how i use Genshi to iterate over actions and include a template to display action details. I use the same template in other places to avoid duplication.


tg.defaultview = "genshi"


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      "" >
<html xmlns=""
<xi:include href="master.html"/>
    <xi:include href="action.html" py:for="action in project.actions"/>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns=""

<body py:strip="">

5 Responses to From Kid to Genshi – Changing template language

  1. Ian Ozsvald says:

    Here’s a quick hat-tip to you, I mention your blog (this entry is shown) in my latest ShowMeDo series. In this 2-part set I introduce useful on-line resources for new Python programmers:

    Cheers, and good luck with the blog,

  2. Matthew says:

    Thanks, that’s useful. Would you be able to share your master.html as well? Thanks.

  3. Florian says:

    If you’re interested in genshi and you also do a lot of dhtml and you don’t want to throw around html fragments between the server and the client AND you’d also don’t like assembling markup by hand in javascript then Genshi2JS could interest you 🙂

  4. C Ring says:

    Thank you for posting this! this has gone a long way toward helping me resolve my problem!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: