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!

2 Answers 2

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);
2
  • If I do that I get a blank page. Nothing else renders, no header, no content, nothing... Commented Mar 5, 2012 at 19:08
  • @GergelyCsata I've re-written the answer, the code's tested and should work fine for what you want
    – Clive
    Commented Mar 5, 2012 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>

3
  • 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. Commented Mar 5, 2012 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
    Commented Mar 5, 2012 at 19:27
  • Yea I wanted to get the block once without a title. But thank you for the general idea! Commented Mar 5, 2012 at 20:10

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.