[Zope] This document's folder's URL?

k_vertigo@yahoo.com k_vertigo@yahoo.com
Tue, 18 Apr 2000 22:15:38 -0400


Hello All

the problem:  Lets take a step back and look at whats going on here. absolute_url() is a method that
gives you the URL of the object by/on which it is called. it is available to all zope objects, (as
are quite lot of other stuff that is documented only in the ZQR at zdp.zope.org and the source).  In
your case your rprobably have this menu stuck in your standard_html_header/footer. the problem is
that your calling absolute_url unqualified from a dtml method. dtml methods act on their containers
and are acquired down through the object tree/database. so the result you're seeing is calling
absolute_url on the various subfolder that you're viewing.  placing it in a document will stop the
urls from changing since the document is basically alling the method on itself, but this really
isn't a solution.

solutions: they're are a couple
    1. you can qualify the call to absolute_url. i have a site where i have a couple folders sitting
off the root
directory which looks like this ( i hope netscape doesn't mangle this)

    ---> ROOT
                -->Sports
                -->Users
                -->News
                         --> World_News
                         -->  Tech_News

my menu in my standard_html_header gets urls to them by qualifying them like
<dtml-var "Sports.absolute_url()">, <dtml-var "News.World_News.absolute_url(_.None, _)">

(the second one is an explicit call to the method, to avoid NameErrors.)

i'm not sure if you can do this with the entity syntax (&)

    2. another option is to play around with the BASE(0-N) and URL(0-N) variables.  try a <dtml-var
REQUEST> on a blank document to get a feel for them.

    example: <a href="<dtml-var BASE0>/News/World_News/">

    this solution really isn't optimal as your're basically hard-coding you're URLs which kinda
    defeats the purpose of using the zope machinery to make you're life easier, although it
    can save some typing.


    3. another option is to call the namespace directly with the folder name you want to display
    and call absolute_url on it. i guess this is really a variiation on solution 1.

    example:  <dtml-var "_['World_News'].absolute_url()">


Hope that helps,

Cheers

Kapil

    Problem with both of these is that they need to be mod. if you make any major site changes.
Nolan Darilek wrote:

> >>>>> "Michel" == Michel Pelletier <michel@digicool.com> writes:
>
>     Michel> you lost me.  absolute_url() in a method will render the
>     Michel> URL to the folder that contains the method.  absolute_url
>     Michel> in a document will render the absolute url of the
>     Michel> document.
>
> Hmm. Here is the source of a "menu" method:
>
> <a href="&dtml-absolute_url;/../../">Main</a><br>
> <a href="&dtml-absolute_url;/articles/">Articles</a><br>
> <a href="&dtml-absolute_url;/fiction/">Fiction</a><br>
>
> On the index_html in the folder which contains this method, that code
> renders:
>
> <a href="http://ethereal.dyndns.org/nolan/writing/index_html/../../">Main</a><br>
> <a href="http://ethereal.dyndns.org/nolan/writing/index_html/articles/">Articles</a><br>
> <a href="http://ethereal.dyndns.org/nolan/writing/index_html/fiction/">Fiction</a><br>
>
> When I click on a link, 'Articles' perhaps, the articles folder is
> entered, with 'menu' being acquired. The rendering in
> articles/index_html is:
>
> <a href="http://ethereal.dyndns.org/nolan/writing/articles/index_html/../../">Main</a><br>
> <a href="http://ethereal.dyndns.org/nolan/writing/articles/index_html/articles/">Articles</a><br>
> <a href="http://ethereal.dyndns.org/nolan/writing/articles/index_html/fiction/">Fiction</a><br>
>
> So it looks as if absolute_url doesn't use the URL to the folder in
> which the method is defined, since the /articles/ shouldn't be before
> the ..'s, or am I doing something incorrect?
>
> Now we'll copy the above code into a DTML document of the same
> name. Here is its rendering in writing/index_html:
>
> <a href="http://ethereal.dyndns.org/nolan/writing/menu/../../">Main</a><br>
> <a href="http://ethereal.dyndns.org/nolan/writing/menu/articles/">Articles</a><br>
> <a href="http://ethereal.dyndns.org/nolan/writing/menu/fiction/">Fiction</a><br>
>
> And, again when clicking on articles:
>
> <a href="http://ethereal.dyndns.org/nolan/writing/menu/../../">Main</a><br>
> <a href="http://ethereal.dyndns.org/nolan/writing/menu/articles/">Articles</a><br>
> <a href="http://ethereal.dyndns.org/nolan/writing/menu/fiction/">Fiction</a><br>
>
> Which seems to behave as I'd think it should. The only change was that
> menu is now a DTML document as opposed to a method, and the links now
> behave as I would expect. IIRC this is Zope 2.1.4. Is this a bug? (I
> think the problem also occurs with URL#.)
>
> _______________________________________________
> 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 )