I've been using a whitelist/blacklist PHP script to control the display of 2 different menu blocks, and its becoming bloated.

Menu_block 1 is the primary menu. Menu_block 2 is the supplementary menu.

I'm trying set the block visibility for Menu_block 1 via PHP - IF Menu_block 2 exists return FALSE, else return TRUE. Print Menu_block 1 unless Menu_block 2 exists.

PHP visibility for Menu_block 1

  if(isset($block = module_exists('menu_block', 'block', '2')) {
    return FALSE;
  return TRUE;

I'm not even sure if this is actually possible.

3 Answers 3


I had the same issue and resolved it by removing one of the blocks by calling template_preprocess_page() in a custom module or in your theme's template.php. What I do is check to see if both blocks exist on the page, and if so, call unset() on the block I want to remove:

function mymodule_preprocess_page(&$variables) {
//Remove secondary menu block if tertiary menu block is on the page
if(!empty($variables['page']['sidebar_first']['menu_block_tertiary']) && !empty($variables['page']['sidebar_first']['menu_block_secondary'])) {

The indexes in your $variables array will most likely be different. On my site, 'sidebar_first' is the region in my theme where my menu blocks (menu_block_primary and menu_block_secondary) are placed. If you're not sure what your variables are, you can use a call to dpm($variables) to find them (Make sure you you have the devel module enabled) like so:

function mymodule_preprocess_page(&$variables) {

As per your last phrase in your question, the Bean module is a potential alternative you might want to consider. Here is a quote about its project page:

Think of a Bean as a method to provide new types (compared to node this would be a content type) which then provides an add content interface to create as many blocks as you require (see screenshot below). The bean content can then be placed around the site just like any other block.

There are quite a few other modules that integrate with the Bean module also.


Check if the block content menu items exist, then show the block.

    $block1 = module_invoke('menu_block', 'block_view', '1');
    $block2 = module_invoke('menu_block', 'block_view', '2'); 
    if ($block1['content']['#content'] == null ) {
        print render($block2['content']);
    } else {
        print render($block1['content']);

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.