You are here

function theme_list_table in Util 7

Returns HTML for a list as a multi-column table.

$list = array_map('filter_xss', array_values(module_list(FALSE, FALSE, TRUE)));
echo theme('list_table', array(
  'items' => $list,
  'columns' => 5,
));

Parameters

$variables: An associative array containing:

  • columns: The number of columns desired.
  • items: an array of items. Generally a simple list, but may be any data recognized by theme_table.
  • empty: The message to display if list does not have any rows.

Example:

1 call to theme_list_table()
quick_list_page in contribs/quick_list/quick_list.module
The main list function.

File

contribs/quick_list/quick_list.module, line 117
Provides a debugging summary of modules that are enabled.

Code

function theme_list_table($variables) {
  $defaults = array(
    'columns' => 2,
    'items' => array(),
    'empty' => t('The list is empty'),
  );
  $variables = array_merge($defaults, $variables);
  $cols = $variables['columns'];
  $list = $variables['items'];
  $addvals = ($cols - count($list) % $cols) % $cols;
  for ($i = 0; $i < $addvals; ++$i) {
    $list[] = "&nbsp;";
  }
  $count = count($list);
  $len = $count / $cols;
  $rows = array();
  for ($i = 0; $i < $len; ++$i) {
    $row = array();
    for ($j = $i; $j < $count; $j += $len) {
      $row[] = $list[$j];
    }
    $rows[] = $row;
  }
  return theme('table', array(
    'rows' => $rows,
    'empty' => $variables['empty'],
  ));
}