[Zope] Generating links from a list
The other week someone provided me with this snippet of code for generating links from a list containing a description and a link:- span tal:define=opts python:here.lib.parse_file(file=context.links,sepr=',',clone=1) tal:block repeat=opt opts lia tal:content=python:opt[1] tal:attributes=href python:opt[0]/a/li /tal:block /span This works fine, but now that I have used it in a template I'm finding that the link is being prepended with the location of the new object after selecting the original link. ie invoking the code above creates a link such as:- http://www.mysite.org/links/org-1 After selecting org-1 the new page displays as:- http://www.mysite.org/links/org-1/links/org-1 Is there something in the code above which generates the full URL? My links list consists of simple lines such as org-1,First link org-2,Second Link org-x,Another Link How do I prepend a hardcoded path to org-1 instead of what is getting generated? I would like to see the link for org-1 being generated as http://www.mysite.org/links/org-1 irrespective of the context. -- John ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Generating links from a list
John Poltorak wrote: My links list consists of simple lines such as org-1,First link org-2,Second Link org-x,Another Link How do I prepend a hardcoded path to org-1 instead of what is getting generated? I would like to see the link for org-1 being generated as http://www.mysite.org/links/org-1 Check the HREF attribute of the links in the generated HTML, and see what you are getting there; unrooted paths are appended (by the browser, not Zope) to the directory component of the source URL. For example: A HREF=org-2Second Link/A in a page at: http://mysite.org/links/org-1 should equate to: http://mysite.org/links/org-2 [If you're still having problems, be explicit on the HREF and the URL you are seeing.] And have you tried simply replacing org-1 in the File with http://www.mysite.org/links/org-1; ? Finally -- from the ZPT snippet, it looks like links is a File object, yet you put it in the URL that you say you wish. It's *sometimes* not a problem given Zope's sibling-acquisition when parsing paths, but could be. G'Luck Nikko ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Generating links from a list
On Mon, Jun 27, 2005 at 10:03:08AM -0600, Nikko Wolf wrote: John Poltorak wrote: My links list consists of simple lines such as org-1,First link org-2,Second Link org-x,Another Link How do I prepend a hardcoded path to org-1 instead of what is getting generated? I would like to see the link for org-1 being generated as http://www.mysite.org/links/org-1 Check the HREF attribute of the links in the generated HTML, and see what you are getting there; unrooted paths are appended (by the browser, not Zope) to the directory component of the source URL. For example: A HREF=org-2Second Link/A in a page at: http://mysite.org/links/org-1 should equate to: http://mysite.org/links/org-2 [If you're still having problems, be explicit on the HREF and the URL you are seeing.] And have you tried simply replacing org-1 in the File with http://www.mysite.org/links/org-1; ? Just tried - and that does work, but the actual site will be changing before long. Finally -- from the ZPT snippet, it looks like links is a File object, yet you put it in the URL that you say you wish. It's *sometimes* not a problem given Zope's sibling-acquisition when parsing paths, but could be. That's right 'links' simply contains a list of objects and descriptions as shown above. When a web page is displayed the objectname is prepended by the directory component. I assumed that Zope did that, but I guess I was wrong. What I really need is to change this line:- tal:attributes=href python:opt[0] to something like:- tal:attributes=href '/mysite/links/' python:opt[0] but I can't figure out how to prepend python:opt[0] with '/mysite/links/'. Any hints? G'Luck Nikko -- John ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Generating links from a list
John Poltorak wrote at 2005-6-27 13:05 +0100: ... This works fine, but now that I have used it in a template I'm finding that the link is being prepended with the location of the new object after selecting the original link. ie invoking the code above creates a link such as:- http://www.mysite.org/links/org-1 After selecting org-1 the new page displays as:- http://www.mysite.org/links/org-1/links/org-1 Is there something in the code above which generates the full URL? Generate absolute (at least server absolute) URLs rather than relative ones... -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )