I'm using the Zen theme and I'm trying to keep as much in code as possible. I'm currently using context to render the block, but I like my php :)

I'm aware of

$block = module_invoke('views', 'block_view', 'name_of_view_display');
print render($block);

// and this
$block = block_load('views', 'name_of_view-name_of_view_display');
$output = _block_get_renderable_array(_block_render_blocks(array($block)));

which works perfectly in most cases. My page.tpl file says

<?php if ($sidebar_first || $sidebar_second): ?>
  <aside class="sidebars">
    <?php print $sidebar_first; ?>
    <?php print $sidebar_second; ?>
<?php endif; ?>

So, clearly, my $sidebar_second variable is empty. I tried to render the block in a theme_preprocess_page function, adding the block to the $vars['page']['sidebar_second'] array, but no luck so far.

Any ideas?

Thanks, Brett

1 Answer 1


If you need to assign block to region programmatically you can implement hook_block_info_alter

function YOURMODULE_block_info_alter(&$blocks, $theme, $code_blocks) {
  if (isset($blocks['views']['name_of_view-name_of_view_display'])) {
    // assign block to region
    $blocks['views']['name_of_view-name_of_view_display']['region'] = 'sidebar_second';
  • Thank you. I was hoping I could do it in the theme layer, but I guess not. That's one thing I like about Wordpress Commented Aug 14, 2013 at 6:26

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.