Rendering renderable arrays in an item_list I'm struggling to get a render-array constructed, and I think it's because of how theme_item_list works. I would be grateful if anyone could help find the problem (or tell me to implement it without item_list!)


  The context: This function is called from my module's
  hook_block_view() to render the content of the block. The module is
  an example module showing how to use a new API. I hope nothing of that
  is needed to answer this point, except that these calls are not made
  from a theme.


The code I have is:

function example_render() {
  $block = array();

/* fill $providers[] ... */

  $items = array();
  foreach ($providers as $metric =&gt; $provider) {
    $value = $provider['value'];
    $class_link = $provider['name'];
    $name_link = $provider['name'];

    // Construct a renderable array wrapper for the template invocation.
    $items[$metric] = array(
      '#type' =&gt; 'container',
      '#attributes' =&gt; array('class' =&gt; array('provider')),
      'info' =&gt; array(
        'providername' =&gt; array(
          '#prefix' =&gt; '&lt;span class="provider-name"&gt;',
          '#markup' =&gt; $name_link,
          '#suffix' =&gt; '&lt;/span&gt;',
        ),
        'providervalue' =&gt; array(
          '#prefix' =&gt; '&lt;span class="metric-value"&gt;',
          '#markup' =&gt; $value,
          '#suffix' =&gt; '&lt;/span&gt;',
        ),
        'metricname' =&gt; array(
          '#prefix' =&gt; '&lt;span class="metric-name"&gt;',
          '#markup' =&gt; $class_link,
          '#suffix' =&gt; '&lt;/span&gt;',
        ),
      ),
    );
  }

  // Finally, bring it all together.. a container with the via text then a list
  // of the providers.
  $block['content'] = array(
    '#type' =&gt; 'container',
    '#attributes' =&gt; array('class' =&gt; array('example')),
    'ttl_text' =&gt; array(
      '#prefix' =&gt; '&lt;h3 class="metrics-title"&gt;',
      '#markup' =&gt; $record['title'],
      '#suffix' =&gt; '&lt;/h3&gt;',
    ),
    'via_text' =&gt; array(
      '#prefix' =&gt; '&lt;span class="metrics-via"&gt;',
      '#markup' =&gt; $via_text,
      '#suffix' =&gt; '&lt;/span&gt;',
    ),
    'metrics' =&gt; array(
      '#items' =&gt; $items,
      '#theme' =&gt; 'item_list',
      '#attributes' =&gt; array(
        'class' =&gt; 'providers-list',
      ),
    ),
  );
  return $block;
}


and this is what I get when run with 9 items in the list:

&lt;div class="example"&gt;&lt;h3 class="metrics-title"&gt;A bacterial sulfonolipid triggers multicellular development in the closest living relatives of animals&lt;/h3&gt;&lt;span class="metrics-via"&gt;via &lt;a href="http://alm.svr.elifesciences.org/articles/info:doi/10.7554/eLife.00013" external="1" target="_blank"&gt;Lagotto article information&lt;/a&gt; courtesy of &lt;a href="http://articlemetrics.github.io/" external="1" target="_blank"&gt;Lagotto&lt;/a&gt;&lt;/span&gt;&lt;div class="item-list"&gt;&lt;ul class="providers-list"&gt;&lt;li #type="container" #attributes="Array" info="Array Array Array" class="first"&gt;&lt;/li&gt;
&lt;li #type="container" #attributes="Array" info="Array Array Array"&gt;&lt;/li&gt;
&lt;li #type="container" #attributes="Array" info="Array Array Array"&gt;&lt;/li&gt;
&lt;li #type="container" #attributes="Array" info="Array Array Array"&gt;&lt;/li&gt;
&lt;li #type="container" #attributes="Array" info="Array Array Array"&gt;&lt;/li&gt;
&lt;li #type="container" #attributes="Array" info="Array Array Array"&gt;&lt;/li&gt;
&lt;li #type="container" #attributes="Array" info="Array Array Array"&gt;&lt;/li&gt;
&lt;li #type="container" #attributes="Array" info="Array Array Array"&gt;&lt;/li&gt;
&lt;li #type="container" #attributes="Array" info="Array Array Array" class="last"&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;


not very inspiring!

The three 'Array' under 'info' in the html here obviously correspond to the providername/providervalue/metricname arrays in the code i.e. the $items array isn't being interpreted as a render array at all.

How can I make this work?
According to https://api.drupal.org/api/drupal/includes!theme.inc/function/theme_item_list/7 theme_item_list is looking for data key so your list item should look like this:

// Construct a renderable array wrapper for the template invocation.
$tmp = array(
  '#type' =&gt; 'container',
  '#attributes' =&gt; array('class' =&gt; array('provider')),
  'providername' =&gt; array(
    '#prefix' =&gt; '&lt;span class="provider-name"&gt;',
    '#type' =&gt; 'markup',
    '#markup' =&gt; $name_link,
    '#suffix' =&gt; '&lt;/span&gt;',
  ),
  'providervalue' =&gt; array(
    '#prefix' =&gt; '&lt;span class="metric-value"&gt;',
    '#type' =&gt; 'markup',
    '#markup' =&gt; $value,
    '#suffix' =&gt; '&lt;/span&gt;',
  ),
  'metricname' =&gt; array(
    '#prefix' =&gt; '&lt;span class="metric-name"&gt;',
    '#type' =&gt; 'markup',
    '#markup' =&gt; $class_link,
    '#suffix' =&gt; '&lt;/span&gt;',
  ),
);
$items[$metric]['data'] = drupal_render($tmp);


That should give you single element:

&lt;li class="first"&gt;&lt;div class="provider"&gt;&lt;span class="provider-name"&gt;test1&lt;/span&gt;&lt;span class="metric-value"&gt;test1&lt;/span&gt;&lt;span class="metric-name"&gt;test1&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;