Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Get the current URL

Quote Reply
Get the current URL
Hi,

I need get the current page's url for to insert in category template.

I tested:

1.- <%g%>

2.- <%Plugins::ULTRAGlobals::Get_Current_URL()%>

3.- and two 'Globals':

3.1.-
sub {
return $CFG->{build_root_url} .$ENV{REQUEST_URI};
}

3.2.-
sub {
use GT::CGI;
my $in = new GT::CGI;
my $url = $in->url(absolute => 1);
return $url;
}

All works fine in dynamic pages but don't work in static pages.

For example, if the URL is: http://www.mysite/category4/subcategory8/more32.html

The results are:

1.- (D) /category4/subcategory8/more32.html
(S) Unknown Tag: 'g'

2.- (D) http://www.mysite/category4/subcategory8/more32.html
(S) http://www.mysite

3.1.-(D) http://www.mysite/category4/subcategory8/more32.html
(S) http://www.mysite

3.2.- (D) /category4/subcategory8/more32.html
(S) nph-build.cgi

How could get the current URL in static pages? Or will be a problem in my site?
Thanks in advance.

JoseML
Quote Reply
Re: [JoseML] Get the current URL In reply to
Hi,

What do you need the current URL for?

May be simpler to just use Javascript:

Code:
<script>alert("Current URL: " + window.location.href)</script>

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Get the current URL In reply to
Hi Andy,

I am developing a category pages that are static but can be expanded dynamically.

The URL of the category page is:

http://www.mysite.com/Category/Subcategory/index.html

And then inside there is a hyperlink that allows expanding the page, showing the hidden part, if the visitor clicks on:

<a href="/cgi-bin/page.cgi?g=Category/subcategory/index.html;advanced=1">[Click here]</a>

For the template, I need something like this:

<a href="/cgi-bin/page.cgi?g=<%g%>;advanced=1">[Click here]</a>


<% g%> works fine if the category page is dynamic but not if it is static.

Do you understand it?

Cheers ,

JoseML
Quote Reply
Re: [JoseML] Get the current URL In reply to
Ok, you could try:

Code:
<%if g%><%g%><%else%><%make_category_url($ID)%><%endif%>

Then a new global called "make_category_url", with:

Code:
sub {
return $DB->table('Category')->as_url( $_[0] ) . "/" . $CFG->{build_index};
}

Untested, but should work :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Get the current URL In reply to
Hi Andy,

Thanks for your help but the new global is not working properly.

When the static URL is:

.../3/132/562/more3.html


The result is:

562.index.html

Cheers,

JoseML
Quote Reply
Re: [JoseML] Get the current URL In reply to
Ok, how about calling it with:

<%if g%><%g%><%else%><%make_category_url($Full_Name)%><%endif%>

Does that work?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Get the current URL In reply to
Thanks Andy, but it's still not working properly.

If the static URL of the category page is:

/cat1/cat2/more3.html

When I use:
<%make_category_url($Full_Name)%>

The result is:
/cat1/cat2/index.html (more3.html is not included)

I have also tried the <%page_on%> tag:
<%make_category_url($Full_Name)%><%endif%>/more<%page_on%>

And the result is:
/cat1/cat2/index.html/more3.html

Only need to delete index.html

Cheers,

JoseML
Quote Reply
Re: [JoseML] Get the current URL In reply to
Totally untested, but try:

make_category_url
Code:
sub {
if ($_[1] > 1) {
return $DB->table('Category')->as_url( $_[0] ) . "/more$_[1]";
} else {
return $DB->table('Category')->as_url( $_[0] ) . "/" . $CFG->{build_index};
}

}

Code:
<%if g%><%g%><%else%><%make_category_url($Full_Name,$paging.current_page)%><%endif%>

Untested, but should do the trick

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!

Last edited by:

Andy: Jan 7, 2011, 4:20 AM
Quote Reply
Re: [Andy] Get the current URL In reply to
Andy, there is a problem:
..................................................................................................

A fatal error has occured:

Can't use an undefined value as a SCALAR reference at /var/www/cgi-bin/tercero/admin/GT/Template.pm line 596.
Please enable debugging in setup for more details.

Stack Trace======================================Links (9170): Links::environment called at /var/www/cgi-bin/tercero/admin/Links.pm line 786 with no arguments.Links (9170): Links::fatal called at /var/www/cgi-bin/tercero/admin/GT/Template.pm line 596 with arguments (Can't use an undefined value as a SCALAR reference at /var/www/cgi-bin/tercero/admin/GT/Template.pm line 596. ).Links (9170): GT::Template::_parse called at /var/www/cgi-bin/tercero/admin/GT/Template.pm line 163 with arguments (GT::Template=HASH(0xbe2adc0), category.html, HASH(0xbd92880)).Links (9170): GT::Template::parse called at /var/www/cgi-bin/tercero/admin/Links.pm line 480 with arguments (GT::Template, category.html, ARRAY(0xbe2aa00), HASH(0xbd92880)).Links (9170): Links::user_page called at /var/www/cgi-bin/tercero/admin/Links/SiteHTML.pm line 212 with arguments (category.html, HASH(0xbd6d5f0), HASH(0xbd92880)).Links (9170): Links::SiteHTML::site_html_category called at /var/www/cgi-bin/tercero/admin/GT/Plugins.pm line 127 with arguments (HASH(0xbd6d5f0), [undef]).Links (9170): GT::Plugins::dispatch called at /var/www/cgi-bin/tercero/admin/Links/SiteHTML.pm line 27 with arguments (GT::Plugins=HASH(0xb0e36d0), site_html_category, *Links::SiteHTML::site_html_category, HASH(0xbd6d5f0), [undef]).Links (9170): Links::SiteHTML::display called at Links::Build::build_category line 855 with arguments (category, HASH(0xbd6d5f0)).Links (9170): Links::Build::build_category called at /var/www/cgi-bin/tercero/admin/GT/Plugins.pm line 133 with arguments (HASH(0xbc779a0)).Links (9170): GT::Plugins::dispatch called at /var/www/cgi-bin/tercero/admin/Links/Build.pm line 30 with arguments (GT::Plugins=HASH(0xb0e36d0), build_category, CODE(0xbc52610), HASH(0xbc779a0)).Links (9170): Links::Build::build called at /var/www/cgi-bin/tercero/admin/nph-build.cgi line 628 with arguments (category, HASH(0xbc779a0)).Links (9170): main::_build_category called at /var/www/cgi-bin/tercero/admin/GT/Plugins.pm line 133 with arguments (GT::SQL::Condition=HASH(0xb5a3990)).Links (9170): GT::Plugins::dispatch called at /var/www/cgi-bin/tercero/admin/nph-build.cgi line 150 with arguments (GT::Plugins=HASH(0xb0e36d0), create_category_changed, CODE(0xb0a1f20), GT::SQL::Condition=HASH(0xb5a3990)).Links (9170): main::build_changed called at /var/www/cgi-bin/tercero/admin/nph-build.cgi line 58 with no arguments.Links (9170): main::main called at /var/www/cgi-bin/tercero/admin/nph-build.cgi line 42 with no arguments.
Quote Reply
Re: [JoseML] Get the current URL In reply to
Oops, was a typo in the above global. Please try the revised one (was missing a ")

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Get the current URL In reply to
Andy, now it works well.

Thank you very much for the help.

Cheers,

JoseML