0

I want to add a block programatically to a page.tpl.php file in my Drupal 7 theme BUT I want it to respect the block's visibility rules.

I'm open to defining new visibility rules in PHP too but it seems whenever I manually invoke a module via code without assigning the block in a region it does not adhere to the block's visibility rules.

  • out of curiousity, what's the purpose of by-passing Drupals block system and manually including it in the theme? – Geoff Sep 16 '14 at 21:05
  • We're creating blocks manually in a custom module and displaying the blocks via the theme. – Matt Sep 17 '14 at 15:48
  • for future reference, that would have been useful information in the question, as well as the current code you were employing. Glad you got it working though – Geoff Sep 17 '14 at 19:29
0

Turns out the solution was in how I was rendering the blocks.

Using this code to render my block added the block to Drupal's "knowledge" of the block being on the page.

$block = block_load($module, $bid);
$blockStuff = _block_get_renderable_array(_block_render_blocks(array($block)));
$output = drupal_render($blockStuff);
print $output;
| 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.