[Zope3-dev] Re: Namespaces considered harmful [Was: tal:define="..." considered harmful?]

Jean-Marc Orliaguet jmo at ita.chalmers.se
Fri Feb 17 06:35:42 EST 2006

Stefan H. Holek wrote:

> My take is that it's not the TAL features (tal:define, python:,  
> whatever) that invite misuse, but the available namespaces.
> I have ported ZPT to Django [1][2] and found the experience  
> surprisingly refreshing. Django naturally does not have anything like  
> "container" or "context" in the Zope sense. And by Django policy,  
> templates don't even get to see the "request". The namespace Zope PTs  
> call "options" becomes the sole, top-level namespace in Django PTs.
> This very effectively keeps me from pulling-in anything not provided  
> by the view in the first place. Everything -- even functions I want  
> to call in, say, conditions -- has to be added by the view. The  
> result is clean and fast templates.
> Stefan
> [1] http://www.djangoproject.com
> [2] http://zope.org/Members/shh/DjangoPageTemplates/1.0.2/readme.txt

Yes, that's true, the thread later evolved towards the same conclusion 
(removing "namespaces" in TAL). If the template needs to pull data from 
different objects, tools or databases directly, then the template/view 
is doing the job of the model.

However the opposite is also true:
the model should not do the job of the view and send information about 
how data should be formatted:

for instance, the model can specify that an item is selected:

   items: [{'id': 1, 'selected': true}]

but not:

   items: [{'id': 1, 'font-style': 'bold'}]

for that matter,  "python: " expressions are important to keep in order 
to be able to map 'selected' to 'font-style: bold' (which is pure 
presentation logic).

"tal:define" is OK if it handles presentation data that only the 
template/view is concerned with.


original message:

> On 11. Feb 2006, at 21:03, Jean-Marc Orliaguet wrote:
>> I almost felt that something was missing, because I'm so used to  
>> inserting "tal:define" in page templates. But now I realize that  
>> this is a mistake.
>> There was a discussion recently on the list about python  expressions 
>> being a bad idea, think twice I would say that  "tal:define" is much 
>> worse:
>> When writing templates, the temptation is great to insert a  
>> "tal:define" to pull some data into the view which is not directly  
>> available in the model represented by the view. But the idea with a  
>> template is that it should represent some data using some markup.  
>> The data is supposed to be already available in some context. If  the 
>> presentation layer needs to cook some extra data, it means  that  
>> there isn't enough presentation data in the first place.
> -- 
> Anything that happens, happens.  --Douglas Adams

More information about the Zope3-dev mailing list