0

I am creating the block using the following code , but i need to dsiplay this block only in specific pages only . How can i achieve this ?

function mailusers_block($op = 'list', $delta = 0, $edit = array()) {
  if ($op == 'list') {
    $blocks[0] = array(
      'info' => t('User Management block'), 
      'weight' => 0, 
      'status' => 1, 
      'region' => 'left',
    );

    return $blocks;
  }

  else if ($op == 'save' && $delta == 0) {
    variable_set('test_block_items', $edit['items']);
  }
  else if ($op == 'view') {
    switch ($delta) {
      case 0:
        // Your module will need to define this function to render the block.
        $block = array(
          'subject' => t('User Group Management'), 
          'content' => mailuser_block_conent(),
        );
        break;
    }
    return $block;
  }
}

function mailuser_block_conent(){
    //create menu links      
     $ret = '<a href="'.$base_url.'/mailusers/adduser">Add User </a>';
     return $ret;
}
3
  • Adrew's answer below is right, but I think your code will not work if you don't correct some errors in your mailuser_block_conent() function. By the way you should name it "mailusers_block_content()"...
    – anou
    Commented Aug 6, 2015 at 9:25
  • Its actually working
    – KTM
    Commented Aug 6, 2015 at 9:37
  • So this line " $ret = '<a href="'.$base_url.'/mailusers/adduser">Add User return $ret;" is missing some code...
    – anou
    Commented Aug 6, 2015 at 11:16

1 Answer 1

0

You need to add 'visibility' option that is equal to 1 and 'pages' option that should be a string that contains one or more page paths separated by '\n', '\r', or '\r\n' for your block information

 $blocks[0] = array(
  'info' => t('User Management block'), 
  'weight' => 0, 
  'status' => 1, 
  'region' => 'left',
  'visibility' => 1,
  'pages' => 'node/1'
);
7
  • for multiple pages , can it given as an array ?
    – KTM
    Commented Aug 6, 2015 at 9:39
  • No, paths should be separated by '\n', '\r', or '\r\n'. You may try to use 'node/1\nnode/2'
    – Andrew
    Commented Aug 6, 2015 at 10:11
  • is it only appicable to node pages, suppose i have a page like site_url/mypage and mypage2 will it work when given the 'page' => 'mypage\nmypage2' ?
    – KTM
    Commented Aug 6, 2015 at 12:16
  • yes, it will work
    – Andrew
    Commented Aug 6, 2015 at 12:18
  • Its not working as such
    – KTM
    Commented Aug 7, 2015 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.