Out of the box, TurboGears supports Kid templates. TurboGears has tight integration for Kid, including an internationalization filter and the use of Kid for widgets. To make migrating to TurboGears easier, TurboGears provides some seamless support for using other template engines, and the project maintains the TurboCheetah plugin providing support for Cheetah. Additionally, TurboGears uses a template engine plugin interface that is shared with other tools, notably Buffet for CherryPy. This provides access to a broad range of pre-built template plugins.
The plugins come in the form of Python Eggs. Once you've easy_installed the plugin, TurboGears will automatically have the ability to render the new templates.
Each template engine has a name or "scheme" to identify it. Kid templates use the "kid" scheme. Cheetah templates use the "cheetah" scheme. By default, TurboGears uses Kid templates, but you can easily use a Cheetah template for a specific method like this:
When rendering the output from this method, TurboGears will notice the template scheme in front and use the appropriate engine for that kind of template.
Using an alternate template engine does not affect how JSON output is handled: you can still choose to output JSON if you've set the allow_json flag.
You can also choose to use a specific engine for all of your application or for a specific path through the "tg.defaultview" config variable. Just set that variable to the extension for the template engine you want. The default is "kid", but you could also set it to "cheetah", for example.
If you have templates that you'd like to reuse that use another template engine, you can write a plugin for that engine easily. There are important parts: 1) a class that provides the plugin functionality and 2) a setup.py that defines the python.templating.engines entry point.
Your call to setup() in setup.py should have a parameter that looks like this:
entry_points=""" [python.templating.engines] schemename = yourpackage.yourmodule:YourPluginClass """,
When you generate an egg of your plugin, the egg will include this entry point in its metadata, which will allow it to be used automatically by TurboGears after installation.