|
|
|
Python Statement Considered Harmful
Martijn Faassen posted two entries on alternative template languages for
Zope 3:
http://faassen.n--tree.net/blog/view/weblog/2005/04/15/0 http://faassen.n--tree.net/blog/view/weblog/2005/04/16/0 The idea behind this is simple: Templates should be data-driven! That is, they should contain no calls, no logic (other than for display) and no other monkey-business at all. It might be easiest to explain why this is a good idea by explaining the problems with NOT doing it. In the beginning there was DTMLDTML was the first template language for Zope. Although a huge improvement on how PHP and ASP templates work, DTMLs syntax, gets ugly pretty quickly. Also, people tended to write complete aplications in DTML. That's OK; it was designed to do that, Python Scripts didn't exist in the first versions of Zope. DTML was the replacement of PHPand ASP. But this quickly tirned ugly and complicated (as it does in ASP and PHP too). Something better was desired.Let there be TALZPT was the next step: Better syntax (it's more verbose, but it is consistent, easy and doesn't degrade into uglyness), and less intelligence and magic. Again, a huge step forward. But if you look at the typical CMF template, you'll see masses of logic, usually complex logic that makes the templates hard to understand and error prone.This happens because templates in Zope2 access objects. They have a context variable where you get the object you are displaying, and you can access the objects attributes and methods. You can also call python expressions. In short, even the new cleaner ZPTs doesn't enforce a strict enough separation between logic and presentation. You can still do too much. So what if we don't do anything of this? We just have data, and display it? Is that feasible with ZPTs? Yes, absolutely. What you need is to somehow call a method before displaying the template, that fetches all the data and does everything that should be done before displaying. Keeping your templates clean.
Luckily, we don't need a new templating system to do this, ZPT allows you to
do too much, but it doens't force you too. You can do this by convention.
|
Nuxeo Bloggers: Log in! Search Nuxeo Blogs
About this blog
Lennart Regebro
Nuxeo Bloggers
Photos and Pictures
|
|
Nuxeo -
Indesko -
Nuxeo 5 Project
All content is copyrighted by their author. CPSSkins is Copyright © 2003-2006 by Jean-Marc Orliaguet. | CPS is Copyright © 2002-2006 by Nuxeo SAS. |