Quantcast
Viewing all articles
Browse latest Browse all 295117

Regression: There is no (resonable) way to programmatically render a block

In D6 you could easily render a block by doing this:

<?php
  $block
= module_invoke($module, 'block',$delta);
 
$output = theme('block', $block);
?>

In D7, module_invoke($module, 'block' ,$delta); returns a non-renderable array and there is no easy way to convert that array into something that drupal_render() can handle correctly. The only way to do this is to take the result of the module_invoke(...) and manually rebuild that array into a renderable array using bits and pieces of code form _block_render_blocks() The closest I have come to getting this to work is:

<?php
    $array
= module_invoke('views', 'block_view', $display);
   
// == array('content' => '...', 'subject' => '...')
   
$block['content'] =$array['content'];
   
$block['#block'] = new StdClass();
   
$block['#block']->subject = array('subject');
   
$block['#block']->region = '';
   
$block['#block']->module = 'views';
   
$block['#block']->delta $display;
   
$block['#theme_wrappers'][] = 'block';
   
$output .= drupal_render($block);
?>

...although even this still doesn't work (trying to figure out why.

All this said, I might be just be missing something because I'm still learning about renderable arrays so please feel free to set me straight and downgrade/close this issue, but if there is no good way to do this, then it is a regression from D6 and therefore critical.


Viewing all articles
Browse latest Browse all 295117

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>