So far I've learned that arg(0), arg(1), arg(2)...etc pulls the argument from the system path,

But

what are the variables for arguments from a path that has been aliased?

example:

I have an aliased path: http://localhost/content-type/title/state-province

How do I pull the state-province from the Url and include it in a dynamic link that is inside a block or panel.

Best practice, I mean.

What is the Drupal way for using arguments from an aliased path?

Comments

cog.rusty’s picture

Something like this:

$normal_path = trim($_GET['q'], '/');
$path_alias = drupal_get_path_alias($normal_path);
$alias_parts = explode('/', $path_alias);

print $alias_parts[0] ."<br />";
print $alias_parts[1] ."<br />";
print $alias_parts[2] ."<br />";
dreadfulcode’s picture

YES!

Details later.

fuldespanto’s picture

It worked for me too, thank you!

solona’s picture

Good timing, thank you. Now to figure out where to put this.

cog.rusty’s picture

Snippets with code like this are used very often,
- in the visibility settings of blocks (after enabling the "php filter"), to make them appear on certain pages.
- in a theme's .tpl.php files or in template.php (for example http://drupal.org/node/139766)

solona’s picture

Thank you, yes I figured it out.

dreadfulcode’s picture

And a great workaround for the time consuming task of creating custom modules. You can create dynamic custom links, which is what most modules basically do anyway.

Follow this thread, as I will post examples of what you can do with this amazing feature.

Does anybody have any good book page/ forum thread links that have other code snippets such as this-- as in: code snippets you just can't live without?

strellman’s picture