[drupal-devel] Question on block creation
Good evening! Is there a "Drupally correct" way to do the following two things? 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). I know how to do this as a kludgy hack, but is there a nice, elegant way to obtain this info? If not, a function like drupal_get_current_path() might be a useful addition to core for 4.7, and probably easy to implement. :-) Kind regards, Scott -- ------------------------------------------------------------------------------- Scott Courtney Drupal user name: "syscrusher" http://drupal.org/user/9184 scott at 4th dot com Drupal projects: http://drupal.org/project/user/9184 Sandbox: http://cvs.drupal.org/viewcvs/drupal/contributions/sandbox/syscrusher
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
On Friday 27 May 2005 01:37, Steven Wittens wrote:
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 ;)
Oh, DUH!!! Why didn't I think of $_GET['q'] before? I'm so used to working with "clean URLs" that I forgot about that GET parameter lurking under the covers. Thanks for the "whack on the side of the head." :-) I thought about doing the arg() things you suggest, and I knew it would work, but I wasn't sure if it was considered the "right" way to do things in Drupal, in case some future version changes the URL structure. I'll go with this approach, but I'll make myself a boolean function so that the "am I in a node?" question is isolated from the rest of my code. Thanks for the tips. :-) Scott -- ------------------------------------------------------------------------------- Scott Courtney Drupal user name: "syscrusher" http://drupal.org/user/9184 scott at 4th dot com Drupal projects: http://drupal.org/project/user/9184 Sandbox: http://cvs.drupal.org/viewcvs/drupal/contributions/sandbox/syscrusher
participants (2)
-
Steven Wittens -
Syscrusher