Using Arguments in a Block View with Views2 and Pathauto

schefz's picture

Hey guys,

Im asking this here cuz you guys are the most knowledgeable drupalers i know! (and im getting no love on #drupal-support) And also, I found Ryan Price's article on DrupalEasy relating to this but not quite the same... http://drupaleasy.com/blogs/ryanprice/2008/06/using-views-2-drupal-6-create-related-pages-block

Ill im trying to do is grab the last part of a url that has been created using pathauto, (ie. /content/arg-value) and pass it to a block view. I know that i have to provide a default argument using php but the sample snippet i found here (and tweaked for my situation ....

$path = drupal_get_path_alias($_GET[‘q’]); //get URL alias $path = explode(‘/’, $path); //break path into an array if ($path[0] == ‘content’ && $path[1] != ”) {   return $path[1]; }

doesnt seem to work. Is content considered an argument? Is there an easier way to grab the argument? Any help would be much appreciated.

Groups:
Login or register to post comments

If the drupal functions

cbosner - Fri, 2009-05-22 13:56

If the drupal functions aren't working, you could just use php..

$url = $_SERVER['QUERY_STRING'];

and then pull out the needed parts


Thanks for the input

schefz's picture
schefz - Fri, 2009-05-22 15:13

Thanks for the input cbosner.

it appears that it was just a copy paste error. an extra space caused the issue.
The copy & paste friendly version is as follows::

$path = drupal_get_path_alias($_GET['q']); //get alias of URL
$path = explode('/', $path); //break path into an array
//user print_r($path); to see what the $path array looks like
if ($path[0] == 'content' && $path[1] != '') {
  return $path[1];
}


What about using the arg() function?

rightsprocket's picture
rightsprocket - Fri, 2009-05-22 15:19

Can you use the arg() function?
http://api.lullabot.com/arg

IE: return arg(2); //Where 2 is the third object in the path
www.rightsprocket.com


It's generally not a good

liberatr's picture
liberatr - Thu, 2009-05-28 16:48

It's generally not a good idea to test against the URL Alias, which is what @rightspricket was getting at. Aliases can change, but arguments will not. It's more sound to base your logic on arg().

Normally, one would check the drupal arguments, like node/305/edit would be : arg(0) == "node", arg(1) == "305", arg(2) == "edit", and so on...

What content are you trying to get at?

Ryan Price
DrupalEasy


I was trying to pass the

schefz's picture
schefz - Fri, 2009-06-05 06:45

I was trying to pass the name of an artist to a block so that the block would show all art pieces by that artist. As seen here:: http://www.skinnybuddha.com/content/swamburger

It works as long as the content creator spells the name of the artist correctly... I know that's not foolproof, but the content creators are me and one other person so it works for now..


Yeah, but content/swamburger

liberatr's picture
liberatr - Fri, 2009-06-05 12:59

Yeah, but content/swamburger is actually an alias to node/37 or whatever... the argument you should be looking for is not the title, but the node ID. The node ID will never fail.

I guess I would need to see your code. Aren't you coming to the Community Helpdesk?

Ryan Price
DrupalEasy