There seems to be multiple ways of printing a drupal 7 block via php input filter. What is the most efficient way of printing a drupal block in Views header or Views footer attachment of a global text php input filter?

2 Answers 2

  1. Try this module https://www.drupal.org/project/views_block_area - it allows insert any block into the view's header or footer.
  2. Another way using code

    $blockObject = block_load('module', 'delta');
    $block = _block_get_renderable_array(_block_render_blocks(array($blockObject)));
    $output = drupal_render($block);
    print $output;

For Drupal 7 :

$block = module_invoke('block', 'block_view', 30); print render($block['content']);

@arg 1 : module name
@arg 2 : hook name like block_view, block_info
@arg 3 : id or delta of the block e.g 30, map-block_1

Keep in mind that you can't just copy and paste that code and put in just the block_id number. The module name corresponds to the module's block your are trying to output. In my case my module name was: "dfp" (its an ads related module). And "block_view" is the hook you have to use that manages the blocks for that module. And the delta id # doesnt necessarily have to be a number, in my case it was this: "smt_180x150_2"

Preview of how my views footer looked with custom block output: http://prntscr.com/5qttl8

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.