Forum OpenACS Q&A: Getting URL

Collapse
Posted by Alex Lloyd on
Hi

I'm trying to find the command that will let me set to default URL path (http://127.0.0.1:8000)

Say I'm in the Notes package (http://127.0.0.1:8000/notes) and in one of my tcl files in the notes package i want to go directly to another package (say http://127.0.0.1:8000/forums) then how can i get there using this sort of command?

set url "<a href=\"/forums\">Forums</a>"

because when I put this in my adp file, it goes to: http://127.0.0.1:8000/notes/forums instead

Can anyone help?

Thanks, Alex

Collapse
2: Re: Getting URL (response to 1)
Posted by Tilmann Singer on
First of all, try to avoid putting together html in tcl files when possible (yes there are tons of bad examples in the toolkit unfortunately). Rather do it like that:

.tcl:
set some_url "/foo"

.adp:
<a href="@some_url@">Bla</a>

You don't need to specify your servername in a link that refers to a location on the same server. And if your link starts with a slash then it starts to resolve from the server root, so your example '/forums' should actually work, you propably have a typo somewhere.

Collapse
3: Re: Getting URL (response to 1)
Posted by Pavel Boghita on
my guess is that you could try:
# set url "<a href=\"../forums/">Forums</a>"
Collapse
4: Re: Getting URL (response to 3)
Posted by Pavel Boghita on
what I meant above was use ../forums/ rather than /forums/ which will take you in /notes/forums/.
'..' stands for parent directory.
Collapse
5: Re: Getting URL (response to 4)
Posted by russ m on
If you are in /notes/ and an URL links to /forums following that link will *not* take you to /notes/forums/ unless you're using a very broken browser (which would surprise me). If the link target starts with a slash it is locked to the root of the server URL tree.

Take a look at the source of the served HTML page where this link is - I'd be pretty confident that the link target is not actually coming through as "/forums"...

Collapse
6: Re: Getting URL (response to 1)
Posted by bill kellerman on
Check the aolserver tcl api at http://www.aolserver.com/docs/devel/tcl/api/conn.html#ns_conn

From the docs:
"ns_conn location returns the location string for this virtual server in the form: protocol://hostname[:port]"

In your tcl file, set hostlocation [ns_conn location].
In your adp file, display <a href="@hostlocation@/forums/">mesgag ba0rd</a> for the appropriate location.

[note that ns_info location is obsolete.]

You can also use relative also as has been mentioned  (../forums, ../notes).

...might be a better way to do this.  check the genius bar.

Collapse
7: Re: Getting URL (response to 1)
Posted by Don Baccus on
It's better to use ad_conn rather than ns_conn, that way you don't have to change your code if we later decide to massage the ns_conn value for OpenACS use (for those items which don't exist in ad_conn we pass through the ns_conn value).