Can someone help me understand how to set certain blocks on different urls?
Maybe an example?

Thank you

Comments

nevets’s picture

If you mean controlling block visibility based on the url/path is pretty straight forward. If you don't have clean urls your paths are going to look like http://www.example.com/index.php?q=some/path/to/act/on, with clean urls that would be http://www.example.com/some/path/to/act/on. The part of the url after your sites domain is a Drupal path. The first part (some) can be retrieved with arg(0), the nect (path) with arg(1), etc. So for example to show a block that appears when showing a single node (any one) you could do something like

// Look for paths of the form node/{nid} where {nid} is a number
// Note we are going to return false if the path has any additional
// parts as in the case of editing the node.  You can
// drop the '&& ! arg(2)' part if you want it to return true when editing a node

if ( arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2) ) {
  return TRUE;
}
else {
  return FALSE;
}

Note arg() returns the parts of the unaliased path.