[Zope3-dev] Number of languages in Zope 3

Steve Alexander steve@cat-box.net
Wed, 09 Apr 2003 10:05:26 +0200


> I don't know how current Zope first-timers get along with ZPT, but 
> considering that ZPT is much more complex in syntax I can't believe that 
> things have become better now.

Would you explain why you think ZPT is much more complex in syntax?


> Even for seemingly simple things it 
> might be necessary to get into python-style syntax. And then why not 
> learn it from scratch?

If you need to do these things, you should learn Python and write a 
Python view class to support your page template.
I believe it is very easy to do this.


> One example: If you just need to place an image in a ZPT template, the 
> syntax (at least one of the hundreds of possibilities) is
> 
> <img tal:replace="structure here/Imagefolder/imagename" src="" />
> 
> This is already quite challenging because of the "structure" directive 
> you need, which is hard to explain to a beginner.

I use this explanation:

   In a page template, special characters like '<' get replaced with
   their HTML entity like '&lt;'.
   Use the word "structure" at the start of an expression if you want
   to turn off this behaviour for that expression.


> But now you want to add a custom title attribute. Just because of this 
> you have to switch to a completely different syntax:
> 
> <img
>   tal:replace="structure 
> python:here.Imagefolder.imagename.tag(title='MyTitle')"
>   src="" />
 >
> This is even hard to get for somebody who knows Python because you are 
> limited to having to use single quotes in the brackets due to some 
> limitation of the TAL parser.

I'd suggest writing this as a method in a supporting view class.


> Well, there is a path-based alternative, but now it's getting really ugly:
> 
>   <img tal:attributes="
>     src here/Imagefolder/imagename/absolute_url;
>     width here/Imagefolder/imagename/width;
>     height here/Imagefolder/imagename/height;
>     alt here/Imagefolder/imagename/alt"
>     title="MyTitle" />

That's a really good point.

Maybe we could introduce a variant called tal:attributesfrom.

So,

   <img tal:attributesfrom="here/Imagefolder/imagename/tagdict"
        tal:attributes="title string:My Title" />

The idea is that you supply tal:attributesfrom with an expression that 
resolves to a dict or something similar. The attributes for the tag are 
filled from that dict except when they are overridden by an attribute 
from tal:attributes.

You could remove an attribute with

   tal:attribute="attributename nothing"

Then, the class for images can be extended to have a tagdict method.
In Zope 3, this would be dealt with by a view.

Replace 'tagdict' and 'attributesfrom' with better names if you think of 
some.


> Now we just have two problems left:
> 
> a) the "structure" keyword that is really hard to get

I think my explanation is pretty clear.


> b) the fact that we now get into trouble if the image is called 
> "imagename.gif" ... (one, not completely satisfying solution would be to 
> use "/" instead of dots, but allow calling methods(), something like:
 >
> here/Imagefolder/imagename/tag()

Does my 'attributesfrom' proposal help?


> So the bottom line is that the current DTML and ZPT syntax is a mess ... 
> :-(

Ok. Personally, I like ZPT syntax a lot.

--
Steve Alexander