I'm trying to render a block in my module that contains both a form and a list of links. I can display one or the other correctly, but apparently do not understand the render array format well enough to get them both rendered at the same time (one above the other) in the same block. Using Drupal 7.4
Example for setting block content to show a list:
$block['subject']='Title';
$items= // code that generates a list of links into an array
$theme_args=array('items'=>$items,'type'=>'ul');
$block['content']=theme('item_list',$theme_args);
return $block;
Example for setting block content to show a form:
$block['subject']='Title';
$block['content']=drupal_get_form('mymodule_myform_function');
// call function that returns the usual form array
return $block;
Each case works fine individually for me. How can I combine the form and the list into one block['content'] array so it can be rendered in one block? Thanks in advance.
I think this should work, I haven't tested though:
$block = array(
'items' = array(
'#markup' => theme('item_list', $theme_args);
),
'form' = drupal_get_form('mymodule_myform_function');
);
$block['content'] = $block;
It is a little counter-intuitive, drupal_get_form
returns a form render array, however theme()
returns markup.
You could always do this (terrible solution) but it isn't advised as its highly inefficient and goes against everything that Drupal intends for you to do:
$block['content'] = theme('item_list', $theme_args) . render(drupal_get_form('myform'));