In some of my projects I need one of the trimmed menu's te be open if no other menu is shown. For instance when a system page is shown (like search/node or contact).
I created a code-snippet to make this happen in the original (not-trimmed) block: this block opens when no trimmed block is shown.
Maybe this can be added in to make other happy users even more happy.

<?php
  // get all trimmed menu blocks
  $blocks = menu_trim_block('list');
  if (is_array($blocks))  {
    foreach($blocks as $mid => $info) {
      $data = menu_trim_block('view', $mid);
      // if block is shown don't show the default block
      if ($data) {
        return FALSE;
      }
    }
  }
  // no trimmed menu present, so show this block
  return TRUE;
?>

Now this code is added in the settings part of the block (in administer >> blocks) on the bottom in visibility. Attention: use "use PHP code".
Thanks for this smart module.

Comments

NancyDru’s picture

Status: Active » Postponed (maintainer needs more info)

I'm kind of confused as to how to use this; I assume it belongs in the TI Blocks contrib. I'm also wondering if it might fit better with #366788: Modify a block programatically before display.

PROMES’s picture

Hello Nancy,

I use it with menu-trim, not taxonomy image, since for me it is logically connected with trimmed menus. So please put this comment back to module menu-trim.
I use trimmed menus in several projects together with primary menu's. When somebody selects, for instance, the contact link in the primary menu, none of the trimmed menu's will be shown. In that case I mostly like to have a default menu that otherwise is trimmed.
For me it could be an extra option in the menu-trim settings. Now we have "never trim", "allow trim" and "allow trim, hide when inactive". If we have an extra option "allow trim, hide when inactive, set as default" (only allowed for one menu ??), my code can show this menu whenever no other side menu is selected. That exactly the way I use it, but with my code I have to put it in the original menu-block to select this block only if no trimmed menu will be shown.
So, I my view, taxonomy image (a module I also use), doesn't have to do nothing with this code. And I was looking at #366788, but couldn't link my intention to that project either.

An example you can see on www.dosgg.nl/search. The CompUsers menu will be shown thru my code. If you press Home in the primary links the same menu will be shown by menu-trim. If you go to another primary link (except eshop --> external site) this menu wil not be shown.

PROMES’s picture

Project: Taxonomy Image » Menu Trim
Version: 5.x-1.5 » 5.x-1.0

Changed to menu trim.

Simon Georges’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

This version of Menu Trim is not supported anymore. The issue is closed for this reason.

Please upgrade to a supported version and feel free to reopen the issue on the new version if applicable.