Drupal – Get URL Arguments in Custom module or Views Template

You can get the URL arguments in custom module or views template files. Create a custom module and use the hook_nodeapi to print the URL arguments.

/**
 * Implementation of hook_nodeapi()
 */
function custom_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'view':
      print arg(0);
      print "<br/>";
      print arg(1);
      break;
    }
}


 

Open a browser and go to an existing node. The 1st and 2nd arguments are shown.

 

You can also called the arg() method the get the URL arguments in Views template too.

Done =)

Reference: Drupal – Getting node id from view to customise link in block

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.