1

I have a block which include a view which is based on node.tpl.php, and I want to change the mark up in the node.tpl.php file just for a specified block.

function theme_preprocess_node(&$variables) {
  $block = unknown_way_to_get_it();
  if ($block->region == "product_stream") {
    $variables['theme_hook_suggestions'][] = 'node__productstream';
  }
}

How do I get a block from the preprocess function?

1

You can't get access to a block object from a node preprocess hook; the context simply isn't passed down the chain.

As you're using a view, though, you can get hold of the View object, and test the name/display id. The basic idea would be:

function theme_preprocess_node(&$variables) {
  if (!empty($variables['view'])) {
    if ($variables['view']->name == 'some_view' && $variables['view']-> current_display == 'block_1') {
      $variables['theme_hook_suggestions'][] = 'node__productstream';
    }
  }
}
| improve this answer | |

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.