This document's folder's URL?
I've recently restructured my Zope site in order to take advantage of acquisition by moving page-specific code into other methods while leaving site-wide formatting in standard_html_header and footer. I'm running into a problem, though. I have a menu DTML method which contains page-specific sidebars. Though this menu often changes, it would be great if I could use acquisition to minimize the number of menu methods. However, if I have a folder in which a menu method from a parent is acquired, I can't think of a way to make URLs absolute. Right now I'm doing: <a href="../">Home</a><br> ... But, it's quite obvious what happens in descendants; ../ no longer links to my homepage, and none of the relative links work. So, is there a variable or method which creates an absolute link to the folder in which the current document resides, thus allowing me to use acquisition and avoid modifying menus whenever my structure deepens? So, I could do something like: <a href="<dtml-var folder_url>/articles/">Articles</a><br> and have that code work, no matter how many levels down 'menu' is acquired?
Nolan, Perhaps something like: <a href="<dtml-var expr="this().absolute_url()">/Articles">Articles</a> This can be shortened to: <a href="<dtml-var absolute_url>/Articles">Articles</a> And can be further shortened to: <a href="&dtml-absolute_url;/Articles">Articles</a> On Mon, 17 Apr 2000, Nolan Darilek wrote:
I've recently restructured my Zope site in order to take advantage of acquisition by moving page-specific code into other methods while leaving site-wide formatting in standard_html_header and footer. I'm running into a problem, though.
I have a menu DTML method which contains page-specific sidebars. Though this menu often changes, it would be great if I could use acquisition to minimize the number of menu methods. However, if I have a folder in which a menu method from a parent is acquired, I can't think of a way to make URLs absolute. Right now I'm doing:
<a href="../">Home</a><br> ...
But, it's quite obvious what happens in descendants; ../ no longer links to my homepage, and none of the relative links work.
So, is there a variable or method which creates an absolute link to the folder in which the current document resides, thus allowing me to use acquisition and avoid modifying menus whenever my structure deepens? So, I could do something like:
<a href="<dtml-var folder_url>/articles/">Articles</a><br>
and have that code work, no matter how many levels down 'menu' is acquired?
_______________________________________________ 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 )
"Chris" == Chris McDonough <chrism@digicool.com> writes:
Chris> Nolan, Perhaps something like: <snip> This works nicely, with one minor gotcha: it seems that the item on which &dtml-absolute_url; appears needs to be a DTML document. Otherwise, it seems to point to the method's ID concatenated onto the current absolute URL. And, one partially non-Zope question: currently, to link to my main website from a subfolder, I have a URL which looks like: <a href="http://www.mysite.com/nolan/folder/menu/../../">Home</a> First, is this legal HTML, or will browsers barf on this? And, is it somehow possible to treat &dtml-absolute_url; as a list of objects to do something like (pseudopython): <dtml-var "string.join(&dtml-absolute_url;[:len(&dtml-absolute_url;)-2])"> since the URL of my homepage will always be two levels higher than the URL to the menu document?
Nolan Darilek wrote:
"Chris" == Chris McDonough <chrism@digicool.com> writes:
Chris> Nolan, Perhaps something like:
<snip>
This works nicely, with one minor gotcha: it seems that the item on which &dtml-absolute_url; appears needs to be a DTML document. Otherwise, it seems to point to the method's ID concatenated onto the current absolute URL.
you lost me. absolute_url() in a method will render the URL to the folder that contains the method. absolute_url in a document will render the absolute url of the document.
And, one partially non-Zope question: currently, to link to my main website from a subfolder, I have a URL which looks like:
<a href="http://www.mysite.com/nolan/folder/menu/../../">Home</a>
First, is this legal HTML,
yes.
or will browsers barf on this? And, is it somehow possible to treat &dtml-absolute_url; as a list of objects to do something like (pseudopython):
<dtml-var "string.join(&dtml-absolute_url;[:len(&dtml-absolute_url;)-2])">
There is a list of objects from you to the root folder called PARENTS. 'You' are PARENTS[0], your parent is PARENTS[1], your grandparent is PARENTS[2], and the root folder is PARENTS[-1] (the last element in the list). <a href="<dtml-var "PARENTS[-1].absolute_url()">">This link goes to the root folder.</a> Also, there is URLx. URL is your URL. URL1 is the URL of your parent. URL2 is the URL of your grandparent and so on. <a href="<dtml-var URL1>">Click to go up one parent.</a> -Michel
"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#.)
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 )
Nolan Darilek wrote:
I've recently restructured my Zope site in order to take advantage of acquisition by moving page-specific code into other methods while leaving site-wide formatting in standard_html_header and footer. I'm running into a problem, though.
I have a menu DTML method which contains page-specific sidebars. Though this menu often changes, it would be great if I could use acquisition to minimize the number of menu methods. However, if I have a folder in which a menu method from a parent is acquired, I can't think of a way to make URLs absolute. Right now I'm doing:
<a href="../">Home</a><br> ...
But, it's quite obvious what happens in descendants; ../ no longer links to my homepage, and none of the relative links work.
So, is there a variable or method which creates an absolute link to the folder in which the current document resides, thus allowing me to use acquisition and avoid modifying menus whenever my structure deepens? So, I could do something like:
<a href="<dtml-var folder_url>/articles/">Articles</a><br>
and have that code work, no matter how many levels down 'menu' is acquired?
Hm, I don't know if I understand this well, but this sounds like a modified breadcrumbs, which makes use of the acquisition PARENTS. Of course the usability depends on the uniformity of the urls in the menu. Perhaps you could use http://www.zope.org/Members/lstaffor/Breadcrumbs Rik
participants (5)
-
Chris McDonough -
kvthan@wm.edu -
Michel Pelletier -
Nolan Darilek -
Rik Hoekstra