I'm trying to hide a block if a user has a certain role or if a certain page is displayed. I've succeeded in the first task, but can't get the second to work using arg(). The designated page is a webform so arg(0) is 'content'. My php is as follows:

global $user;
if (in_array(certain role,$user->roles))
  {
    return FALSE;
  }
elseif (arg(1)=='certain-page')
  {
    return FALSE;
  }
else
  {
    return TRUE;
  }

Hiding the block worked when it was by role alone, but using the arg() condition alone or with role condition doesn't work. I've seen several posts here about using arg() and it seems really straightforward, so what am I missing?

Comments

gbrussel’s picture

<?php
global $user;
if (in_array(certain role,$user->roles) || arg(1) == 'certain-page')
  {
    return FALSE;
  }
else
  {
    return TRUE;
  }
?>
rande03’s picture

thanks for a quick reply. The problem seems to be with arg(). If use it alone without the role condition, it doesn't work either:

global $user;
if (arg(1) == "certain-page")
  {
    return FALSE;
  }
else
  {
    return TRUE;
  }

just to simplify, I tried "if (arg(0) == 'content')", and still no go. it really seems to be the arg() call.

nevets’s picture

There are a couple of things to consider, pages have paths and paths can have aliases.

Paths are of the form 'node', 'node/123', 'node/123/edit', 'admin', etc.

The arg() function returns the parts of the un-aliased path.

In general terms for node based content your check would look something like

if (  arg(0)  ==  'node' &&  arg(1) == '123' ) {
// Match
}
rande03’s picture

Yes! going back to the un-aliased node gets the result I want. Thanks, nevets.

rjdjohnston’s picture

thanks!