Oliver Frommel wrote:
Hi,
so why do these two pieces of code produce different results? (I thought they should print the same, according to the with-tag howto) (the second one prints the title of folder A twice)
<dtml-with A> <dtml-var title><br> <dtml-var "B.title"> </dtml-with>
<dtml-with A> <dtml-var title><br> <dtml-with B> <dtml-var title> </dtml-with> </dtml-with>
Hm, I actually don't know. Some parts of Zope semantics are too obscure in my opinion.. Anyway, it seems to matter if B is a Folder or a DTML Method/DTML Document. If it's a Folder, the second works as you'd expect, and you do get the same result as in the first. If it's not a folder, you get the acquired title from folder A instead (this explains the printing of the same title twice). What I don't understand is why this occurs; perhaps this is because the with tag only works with ObjectManagers (folders) and not with other objects? But this isn't documented anywhere. The bizarre thing is that this hack does give the expected (by you and me) result with DTML Documents: <dtml-with A> <dtml-in "(B,)"> <dtml-var title> </dtml-in> </dtml-with> What the 'in' tag does there is loop through a list containing just B. Now it does display B's title. What also gives the same result is this: <dtml-with A> <dtml-with "_.getitem('B')"> <dtml-var title> </dtml-with> </dtml-with> This may give us a clue on what's going on. The getitem() function looks up a name in the namespace, but does not call it. If B is called, we get the HTML result, which does not have any 'title' property. I think. You can verify this by checking what happens if you do: <dtml-with "'some test string'"> </dtml-with> I don't think it does anything; it just passes silently. If B however is looked up using getitem(), we *do* have a reference to the object, and the with tag does work as expected. I think this explains it, though I wonder why *folders* don't get 'called' and return strings. Some input on this from people more knowledgable than I am would be appreciated. It reflects badly on DTML that something so basic takes me such a long time figuring it out. After all I've been using DTML for almost a year now.. And I'm not stupid. :) Philosophical end rant: If I ever get the time I'd be tempted to work on a DTML 'cleanup' project. DTML is currently *far* too much like Perl and not enough like Python. *some* easy things are very easy, but as a consequence some other easy things become far too hard, or at least look far too complicated. You can spell the same thing in too many ways. The community encourages and praises additions for convenience (like the 'default' option, or the new extended &entity; syntax) but as a result DTML loses its conceptual integrity. It becomes too big and not easy to understand. I understand the argument that DTML shouldn't be used for complicated purposes, and that you should use Python. This is fine and good, but in practice people *do* use DTML for complicated purposes. ZClasses in fact encourage this. DTML should be more like Python. Luckily the Zope framework does allow new objects to be plugged in using something else than DTML, so not all hope is lost. :) Feedback on this rant would be appreciated. First-thing-I'd-get-rid-of-is-the-'_'-ly yours, Martijn