3

I must be missing something here, I hope someone can shed some light on this, but I can't see how to remove blocks when using the Context Reaction - Blocks on the context configuration screen.

I can add blocks using the checkboxes and the add buttons, and I can remove them once added but how do you remove blocks that are already being rendered?

thanks

Jack

1
  • 2
    Please change to a more descriptive title.
    – Letharion
    Commented Jul 24, 2012 at 9:51

4 Answers 4

2

@jack, you can't remove blocks that are already being rendered, but you can show them only on specific pages, which will effectively do what you need.

For example, I had a footer contact form which I want to show on all pages on the site except on the contact page. I used the following steps:

  1. Added a new context called "except_contact".
  2. On the new context editing screen, added a path condition with the path negation operator, "~" (which is specific to contexts): "~contact/info" will activate the context in all paths except contact/info.
  3. Added the global contact block to the footer region.

This does what you need - show the block in all pages except the designated page where the block is effectively removed.

1

If Blocks are being rendered, it's probably because they were enabled in

example.com/admin/structure/block

I usually disable all blocks there which only leaves me with the Main Content. If you need certain blocks across your website, you can create a site wide Context.

0

There's a little X on the right side of the block-item in the regions list of context.

Oh, maybe you mean something different. What do you mean exactly with:

how do you remove blocks that are already being rendered?

Do you think about an "reaction" to remove blocks? In this case you'd have to create another condition and just do not add the particular block.

0

Create a custom module and use this code. Make sure to comment out kpr() functions ... they are only here to help inspect what blocks appear and conditions in the current node.

function mymodule_block_list_alter(&$blocks) {
  foreach($blocks as $bid){
    kpr($bid); // Enable module Devel - identify the block you want to remove
    switch ($bid->delta) {
      case 'block_to_remove': // this is the specific block's delta
        $thisbid = $bid->bid;
        $node = menu_get_object();
        kpr($node);  // Enable module Devel and view what node condition you wish to test for
        // test for the node condition
        $node->field_condition['und'][0]['value']) === "contextual condition" ? $condition = TRUE : $condition = FALSE ;
        // remove block from list if condition is true
        if(!$condition){ unset($blocks[$thisbid]); }
      break;
    }
  }
}

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.