1

Today I found a working php snippet to load block content into a node:

<?php
$block = block_load('block', '1');
$output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
print $output;
?>

Sadly I am not that good with php, and I could not figure out what to add, to remove the block title from rendering. I have no need for that.

Help would be awesome! Thank you in advance!

0

You need to empty the subject of the block which is what Drupal uses to display the title:

// Set the block ID
$bid = 1;

// Load the block
$block = block_load('block', $bid);

// Get the output array
$output = _block_get_renderable_array(_block_render_blocks(array($block)));

// Set the block subject to an empty string
$output['block_' . $bid]['#block']->subject = '';

// Output
print render($output);
  • If I do that I get a blank page. Nothing else renders, no header, no content, nothing... – Gergely Csata Mar 5 '12 at 19:08
  • @GergelyCsata I've re-written the answer, the code's tested and should work fine for what you want – Clive Mar 5 '12 at 19:42
0

I think you can remove the title, if you go directly in the block config page and in the title section you add <none>

  • Of course this would also remove the block title when a block is displayed the normal way; I'm not sure if that is what @Gergely Csata is after. – marcvangend Mar 5 '12 at 19:25
  • In that case, I guess that one of theses function _block_render_blocks, _block_get_renderable_array or will return something with ['#title'] and you can simply unset it. – yvan Mar 5 '12 at 19:27
  • Yea I wanted to get the block once without a title. But thank you for the general idea! – Gergely Csata Mar 5 '12 at 20:10

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.