[drupal-devel] Question on block creation
Syscrusher
scott at 4th.com
Fri May 27 13:17:11 UTC 2005
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
More information about the drupal-devel
mailing list