views:

502

answers:

4

Hi guys,

I'd like to retrieve the current page path alias without the installation's folder arguments. I'm using:

drupal_get_path_alias(request_uri())

But this returns installation/whatever/actual/path and I want to retrieve the actual/path only no matter what installation/whatever is.

Thanks in advance :)

A: 

The path of the node you are on?

http://api.drupal.org/api/function/drupal_get_path_alias/6

if ($node || (arg(0) == 'node' && arg(2) != 'edit')) {
   $system_path = 'node/'.arg(1);
   $current_path = drupal_get_path_alias($system_path);
}

That code will fire on node pages and tell you the page alias.

For more information, you can dump out $_GET and look at the 'q' query string value.

Kevin
A: 

Have you tried $_GET['q']?

ceejayoz
That returns the path, not the alias. Thanks though, I already found it.
ozke
Enable the Global Redirect module and the path should always be that of the alias.
ceejayoz
+1  A: 

Found it. It was actually a mix of both suggestions:

$current_path = drupal_get_path_alias($_GET["q"]);

Thanks though.


Update: the previous solution doesn't always work

Someone suggested using an alternative method:

str_replace(base_path(), '', drupal_get_path_alias(request_uri(), 1));

But, is there any way of doing the same without using the slightly expensive str_replace?

Thanks

ozke
A: 

Maybe you can use base_path() and str_replace like this :

str_replace (base_path(), '', drupal_get_path_alias(request_uri()), 1);

The base_path is saved in the database.

Brice Favre
This also does the trick for any kind of page if it wasn't for the typo.Fixed version is:str_replace(base_path(), '', drupal_get_path_alias(request_uri(), 1));
ozke
My intention was finding a way of doing this without str_replace. Any ideas?
ozke
why you add an argument to drupal_get _path_alias?
Brice Favre
To retrieve the current URL, isn't it?
ozke
no, i use it on the fourth argument of str_replace.
Brice Favre