2

From within a block, I've used the following PHP to add additional blocks inside it:

$content_search = module_invoke('search_api_page', 'block_view', 'content_search');
$user_search = module_invoke('search_api_page', 'block_view', 'user_search');

print render($content_search);
print render($user_search);

When I do so, I get the following warnings:

Warning: Invalid argument supplied for foreach() in element_children() (line 6541 of /var/www/mysite.dev/public_html/includes/common.inc). Warning: Illegal string offset '#children' in drupal_render() (line 5998 of /var/www/mysite.dev/public_html/includes/common.inc). Warning: Illegal string offset '#children' in drupal_render() (line 6008 of /var/www/mysite.dev/public_html/includes/common.inc).

It appears that the problem is tied to the render() function as I can call print_r($content_search) and everything looks good, but I can't render the blocks without these warnings.

3

Blocks aren't render arrays, they're made up of a subject and content key.

You'll probably have better luck referring to those explicitly:

$content_search = module_invoke('search_api_page', 'block_view', 'content_search');
$user_search = module_invoke('search_api_page', 'block_view', 'user_search');

print render($content_search['content']);
print render($user_search['content']);
  • Thanks, that did it -- I've never run into that problem before. – Sean Cunningham Mar 24 '16 at 14:07
1

try it like this:


$content_search = module_invoke('search_api_page', 'block_view', 'content_search');
$user_search = module_invoke('search_api_page', 'block_view', 'user_search');

print render($content_search['content']);
print render($user_search['content']);

or use another method:


$block = block_load($module, $delta);
$render_array = _block_get_renderable_array(_block_render_blocks(array($block)));
$output = drupal_render($render_array);
print $output;

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.