Thursday, January 17, 2008

Changing the default template engine in Turbogears

By default TG uses "kid" as its templating language. To change that go to wiki20/config/app.cfg

and search for
# tg.defaultview = "kid". copy it down and change to antlr_string.
tg.defaultview = "antlr_string"

Change the extension of all your templates to ".st"

start your server again and lo and behold, you have a greeting you at the browser:).

If you are feeling a little naughty, try this:
1. in the plugin make the extesion as ".kid" instead of ".st"
2. But change everything else to use antlr string template.
3. Now your kid templates are rendered by AST.
4. if you carefully chose py:replace and py:strip attributes, you can enclose your AST syntax in that.
5. Now when kid processes those templates, you dont see any of your AST code, when AST processes, you might see some jargon, but you can be careful and test on both engines and get good output :).

What you lose in this process is a strict enforcement of well formedness etc..
But what you gain is a clear line of separation between controller and view.

The only "disadvantage" if any is that the controller should know before hand what the keys used in the template are.

No comments: