[drupal-devel] Question on block creation

Steven Wittens steven at acko.net
Fri May 27 05:37:22 UTC 2005

>1. Obtain the current Drupal path without querying web server variables.
>2. Know whether or not the current page is displaying a node in full-page view
>   *from within a block* (i.e., *not* from within the node content creation).
You either use arg() to access individual path components, or $_GET['q'] 
for the full path. They always point to the real path, not the aliased path.

e.g. Looking at "articles/drupal" aliased to -> "node/5"
arg(0) = node
arg(1) = 5
$_GET['q'] = node/5

To check if you are on a node page:
if (arg(0) == 'node' && is_numeric(arg(1))) {
To check if you are on a node's view tab:
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '') {
(note: the path of the default tab "view" is the that of the parent 
"node/5", not "node/5/view").

Quite simple ;)
Steven Wittens

More information about the drupal-devel mailing list