I'm sure this is a newbie question, so go easy on me :) Anyway, I've finally gotten around to mocking up the python.org website in Zope. I saw some neat code called Breadcrumbs which includes a list of parent links to the page you're sitting on, e.g. Home > Community > On-line PSA Registration Naturally, I modified the DTML to do things a little differently, and one of the things I want to do is to be able to add title abbreviations (i.e. nicknames) to some folders, using them in preference to title or id (I want a sort of nickname_or_title_or_id method). So the idea is to add a property to some folders called `nickname' and use that if it exists, otherwise use the title_or_id. The problem of course is that I do not want `nickname' to be acquired. I figured I could write DMTL like the following to accomplish this: -------------------- snip snip -------------------- <dtml-with folderobj only> <dtml-if nickname><dtml-var nickname> <dtml-else><dtml-var title_or_id> </dtml-else> </dtml-with> -------------------- snip snip --------------------
From the docs, it seems that the `only' tag should stop the name search in enclosing namespaces, but this doesn't seem to work. In my root folder, I include a nickname property, and set it to "Home". In a subfolder (say "psa") I do not have a nickname property, but this DTML method is returning "Home" for both folder objects.
I've also tried substituting the dtml-if test with something like <dtml-if "_.hasattr(folderobj, 'nickname')"> but that didn't seem to make a difference. Is this enough information to help? I'm sure I'm either misunderstanding some simple concept or doing some dumb newbie lose. Any help will be appreciated. Thanks, -Barry
There's a method hasProperty(id) that might help. -- Loren
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Barry A. Warsaw Sent: Wednesday, November 03, 1999 09:01 To: zope@zope.org Subject: [Zope] dtml-with and only
I'm sure this is a newbie question, so go easy on me :)
Anyway, I've finally gotten around to mocking up the python.org website in Zope. I saw some neat code called Breadcrumbs which includes a list of parent links to the page you're sitting on, e.g.
Home > Community > On-line PSA Registration
Naturally, I modified the DTML to do things a little differently, and one of the things I want to do is to be able to add title abbreviations (i.e. nicknames) to some folders, using them in preference to title or id (I want a sort of nickname_or_title_or_id method). So the idea is to add a property to some folders called `nickname' and use that if it exists, otherwise use the title_or_id.
The problem of course is that I do not want `nickname' to be acquired. I figured I could write DMTL like the following to accomplish this:
-------------------- snip snip -------------------- <dtml-with folderobj only> <dtml-if nickname><dtml-var nickname> <dtml-else><dtml-var title_or_id> </dtml-else> </dtml-with> -------------------- snip snip --------------------
From the docs, it seems that the `only' tag should stop the name search in enclosing namespaces, but this doesn't seem to work. In my root folder, I include a nickname property, and set it to "Home". In a subfolder (say "psa") I do not have a nickname property, but this DTML method is returning "Home" for both folder objects.
I've also tried substituting the dtml-if test with something like
<dtml-if "_.hasattr(folderobj, 'nickname')">
but that didn't seem to make a difference.
Is this enough information to help? I'm sure I'm either misunderstanding some simple concept or doing some dumb newbie lose. Any help will be appreciated.
Thanks, -Barry
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope No cross posts or HTML encoding! (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Sorry, I wasn't very explicit in that last message. I used hasProperty(id) in a similar situation, like this: <!--#with "PARENTS[-1]"--> <!--#if "hasProperty('button_on') and hasProperty('button_off')"--> <td class="navd" align="right"> <a href="<!--#var absolute_url-->" onMouseOver="if (document.images) document.bhome.src='/images/<!--#var button_on-->'; return true;" onMouseOut="if (document.images) document.bhome.src='/images/<!--#var button_off-->'; return true;"><img name="bhome" src="/images/<!--#var button_off-->" border="0" vspace="0" WIDTH="117" HEIGHT="39" ALT="<!--#var title_or_id-->"></a> </td> <!--#else--> <td class="navc" align="right"> <A HREF="<!--#var absolute_url-->"><<home</A> </td> <!--#/if--> <!--#/with--> HTH -- Loren
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Barry A. Warsaw Sent: Wednesday, November 03, 1999 09:01 To: zope@zope.org Subject: [Zope] dtml-with and only
I'm sure this is a newbie question, so go easy on me :)
Anyway, I've finally gotten around to mocking up the python.org website in Zope. I saw some neat code called Breadcrumbs which includes a list of parent links to the page you're sitting on, e.g.
Home > Community > On-line PSA Registration
Naturally, I modified the DTML to do things a little differently, and one of the things I want to do is to be able to add title abbreviations (i.e. nicknames) to some folders, using them in preference to title or id (I want a sort of nickname_or_title_or_id method). So the idea is to add a property to some folders called `nickname' and use that if it exists, otherwise use the title_or_id.
The problem of course is that I do not want `nickname' to be acquired. I figured I could write DMTL like the following to accomplish this:
-------------------- snip snip -------------------- <dtml-with folderobj only> <dtml-if nickname><dtml-var nickname> <dtml-else><dtml-var title_or_id> </dtml-else> </dtml-with> -------------------- snip snip --------------------
From the docs, it seems that the `only' tag should stop the name search in enclosing namespaces, but this doesn't seem to work. In my root folder, I include a nickname property, and set it to "Home". In a subfolder (say "psa") I do not have a nickname property, but this DTML method is returning "Home" for both folder objects.
I've also tried substituting the dtml-if test with something like
<dtml-if "_.hasattr(folderobj, 'nickname')">
but that didn't seem to make a difference.
Is this enough information to help? I'm sure I'm either misunderstanding some simple concept or doing some dumb newbie lose. Any help will be appreciated.
Thanks, -Barry
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope No cross posts or HTML encoding! (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Barry A. Warsaw wrote:
The problem of course is that I do not want `nickname' to be acquired. I figured I could write DMTL like the following to accomplish this:
-------------------- snip snip -------------------- <dtml-with folderobj only> <dtml-if nickname><dtml-var nickname> <dtml-else><dtml-var title_or_id> </dtml-else> </dtml-with> -------------------- snip snip --------------------
The 'only' attribute does not stop acquisition, it hides all namespaces on the Nspace stack except the object specified in the 'with'. If that object supports implicit acquisition (and folders do) then you can still acquire an attribute from that object. What you want is a combination of both 'only' and 'aq_explicit': <dtml-with folderobj only> <dtml-with aq_explicit> <= this turns off acquisition.. <dtml-if nickname><dtml-var nickname> <dtml-else><dtml-var title_or_id> <= this won't be acquired either! </dtml-if> </dtml-with> </dtml-with> The outermost with tag may not be necesary, but it does make sure that 'nickname' is not found if it happens to be defined in a previous DTML Nspace. -Michel
Thanks for the suggestion and explanation guys. Just to follow up, Michel's suggestion to use <dtml-with aq_explicit> to turn off acquisition did not work. Loren's suggestion to test on "hasProperty('nickname')" did the trick nicely. For completeness, here's the DTML for my current Breadcrumbs DTML method. -Barry -------------------- snip snip -------------------- <!-- start Breadcrumbs --> <dtml-call "REQUEST.set('rev', [])"> <dtml-in PARENTS skip_unauthorized> <dtml-let item=sequence-item> <dtml-call "rev.insert(0, item)"> </dtml-let> </dtml-in> <dtml-in rev> <dtml-with sequence-item> <a href="<dtml-var absolute_url>"> <dtml-if "hasProperty('nickname')"><dtml-var nickname><dtml-else><dtml-var title_or_id></dtml-if></a> </dtml-with> <dtml-unless sequence-end> > </dtml-unless> </dtml-in> <!-- end Breadcrumbs -->
May I add your implementation to the Breadcrumbs How-To (with attribution of course)? -- Loren
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Barry A. Warsaw Sent: Wednesday, November 03, 1999 14:34 To: Michel Pelletier; Loren Stafford Cc: zope@zope.org Subject: Re: [Zope] dtml-with and only
Thanks for the suggestion and explanation guys. Just to follow up, Michel's suggestion to use <dtml-with aq_explicit> to turn off acquisition did not work. Loren's suggestion to test on "hasProperty('nickname')" did the trick nicely. For completeness, here's the DTML for my current Breadcrumbs DTML method.
-Barry
-------------------- snip snip -------------------- <!-- start Breadcrumbs --> <dtml-call "REQUEST.set('rev', [])"> <dtml-in PARENTS skip_unauthorized> <dtml-let item=sequence-item> <dtml-call "rev.insert(0, item)"> </dtml-let> </dtml-in> <dtml-in rev> <dtml-with sequence-item> <a href="<dtml-var absolute_url>"> <dtml-if "hasProperty('nickname')"><dtml-var nickname><dtml-else><dtml-var title_or_id></dtml-if></a> </dtml-with> <dtml-unless sequence-end> > </dtml-unless> </dtml-in> <!-- end Breadcrumbs -->
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope No cross posts or HTML encoding! (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
The updated version is now available at http://www.zope.org/Members/lstaffor/Breadcrumbs -- Loren
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Barry A. Warsaw Sent: Wednesday, November 03, 1999 16:05 To: Loren Stafford Cc: Michel Pelletier; zope@zope.org Subject: [Zope] Re: Breadcrumbs update (was RE: [Zope] dtml-with and only)
"LS" == Loren Stafford <lstafford@icompression.com> writes:
LS> May I add your implementation to the Breadcrumbs How-To (with LS> attribution of course)?
Sure!
-Barry
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope No cross posts or HTML encoding! (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Barry A. Warsaw wrote:
Thanks for the suggestion and explanation guys. Just to follow up, Michel's suggestion to use <dtml-with aq_explicit> to turn off acquisition did not work. Loren's suggestion to test on "hasProperty('nickname')" did the trick nicely. For completeness, here's the DTML for my current Breadcrumbs DTML method.
Oh did I say <dtml-with aq_explicit>? ;) My bad, this was my wrong suggestion: <dtml-with obj only> <dtml-with aq_explicit> <dtml-if nickname> ... The problem here is that the Nspace stack is masked and obj is pushed on to it. Then, aq_explicit is pushed on top of that, when a lookup for 'nickname' fails in aq_explicit, it drops down to the next object on the stack, which is obj, which *is* an implicit acquirer, so it does find nickname, which is why it doesn't work. What I really meant to say was: <dtml-if "_.hasattr(aq_explicit, 'nickname')"> <dtml-var nickname> <dtml-else> <dtml-var title_or_id> </dtml-if> In either case, Loren's suggestion is probably better and cleaner (but would not work for non property attributes named nickname, you may have a requirement for 'nickname' to be a SQLMethod, for example). -Michel
participants (3)
-
Barry A. Warsaw -
Loren Stafford -
Michel Pelletier