1

I'm working on a Drupal 6 site made by other people, and I need to remove some block on the homepage for my language only.

I'm trying to use a Context and, by use of hook_context_init(), check if the context is active and remove the undesired blocks.

But i have a problem: How can I remove block in a hook function?

I hope my question is clear.

I don't want to hide the blocks with CSS because of the dirty markup..

[RESOLVED] I did a preprocess like:

function wfp_homepage_context_preprocess_block(&$vars, $hook) {
    $to_delete = array('block_delta_1', 'block_delta_2')


    if(in_array($vars['block']->delta , $to_delete)){
        $vars['template_files'][0] = 'block-empty'; 
    }
}

and i add an empty block-empty.tpl.php in my theme.

3

You can use hook_page_alter() to do this. For example, if you wanted to remove the system navigation block from the "sidebar_first" region, you would do something like this:

function MYMODULE_page_alter(&$page) {
  if ($my_condition) {
    $region_name = 'sidebar_first';
    $block_name = 'system_navigation';

    if (isset($page[$region_name][$block_name])) {
      $page[$region_name][$block_name]['#access'] = FALSE;
    }
  }
}
  • I'm sorry but i forgot to say i'm using drupal 6 not drupal 7 T______T So i can't use the hook_page_alter().. any other ideas? – Shyghar May 10 '12 at 7:53
  • I'd like to do this in Drupal 8. Any pointers as to how? That hook was removed. – fritzmg Mar 15 '18 at 12:41
3

[SOLVED] I did a preprocess like:

function module_preprocess_block(&$vars, $hook) {
    $to_delete = array('block_delta_1', 'block_delta_2')
    if(in_array($vars['block']->delta , $to_delete)){
        $vars['template_files'][0] = 'block-empty'; 
    }
    }

and i add an empty block-empty.tpl.php in my theme.

0

The hook you're looking for is hook_block_view_alter(), or it's delta cousin.

You'd check against $module['delta'] to see if it's the block you care about, and then unset the subject and content of $block.

  • I'm working on Drupal 6 and hook_block_view_alter() is a drupal 7+ function.. – Shyghar May 10 '12 at 8:14
0

There doesn't seem to be an easy way to do this in D6. You if you are using the i18n internationalization module, you could define your paths, that are prepended with your language code, as exceptons in the block config menu. so something like es/* for spanish.

Haven't tested myself, just a thought.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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