How do I convert a render array to plain HTML? I have a render array with a list of items.

$array = array(
  'list' =&gt; array(
    '#items' =&gt; $items,
    '#theme' =&gt; 'item_list'
  )
);


I tried to use it with ajax_command_html(), which works perfectly with a simple HTML string, but it doesn't work when it gets a render array. 

Can I somehow convert this render array to an HTML string to use it with that function?
ajax_prepare_response() contains the following code.

$html = is_string($page_callback_result) ? $page_callback_result : drupal_render($page_callback_result);
$commands[] = ajax_command_insert(NULL, $html);
// Add the status messages inside the new content's wrapper element, so that
// on subsequent Ajax requests, it is treated as old content.
$commands[] = ajax_command_prepend(NULL, theme('status_messages'));


So, to achieve the same (i.e. convert a render array into a HTML string), you can call drupal_render() passing the render array to the function.

 $render_array = array(
    '#items' =&gt; $items,
    '#theme' =&gt; 'item_list'
 );

 return ajax_command_html($elector, drupal_render($render_array));


Also theme() would return a HTML string, and you could as well use the following code.

 return ajax_command_html($elector, theme('item_list', array('items' =&gt; $items)));


Since Drupal 8 doesn't have the theme() function anymore, I would use drupal_render() just to make easier to convert Drupal 7 code to Drupal 8.

Keep in mind that drupal_render() is expecting an array; in the case you are calling it from a function that could receive a string as argument, you need to verify you are passing an array to drupal_render(), as the code I shown does.