function theme_item_list

Returns HTML for a list or nested list of items.

Parameters

$variables: An associative array containing:

  • items: A list of items to render. Allowed values are strings or render arrays. Render arrays can specify list item attributes in the #wrapper_attributes property.
  • title: The title of the list.
  • type: The type of list to return (e.g. "ul", "ol").
  • attributes: The attributes applied to the list element.

Related topics

40 theme calls to theme_item_list()
AggregatorCategoryBlock::build in drupal/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php
Builds and returns the renderable array for this block plugin.
AggregatorFeedBlock::build in drupal/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php
Builds and returns the renderable array for this block plugin.
Analyzer::formatMessages in drupal/core/modules/views/lib/Drupal/views/Analyzer.php
Formats the analyze result into a message string.
authorize.php in drupal/core/authorize.php
Administrative script for running authorized file operations.
BookController::bookRender in drupal/core/modules/book/lib/Drupal/book/Controller/BookController.php
Prints a listing of all books.

... See full list

File

drupal/core/includes/theme.inc, line 2348
The theme system, which controls the output of Drupal.

Code

function theme_item_list($variables) {
  $items = $variables['items'];
  $title = (string) $variables['title'];

  // @todo 'type' clashes with '#type'. Rename to 'tag'.
  $type = $variables['type'];
  $list_attributes = $variables['attributes'];
  $output = '';
  if ($items) {
    $output .= '<' . $type . new Attribute($list_attributes) . '>';
    $num_items = count($items);
    $i = 0;
    foreach ($items as &$item) {
      $i++;
      $attributes = array();
      if (is_array($item)) {
        if (isset($item['#wrapper_attributes'])) {
          $attributes = $item['#wrapper_attributes'];
        }
        $item = drupal_render($item);
      }
      $attributes['class'][] = $i % 2 ? 'odd' : 'even';
      if ($i == 1) {
        $attributes['class'][] = 'first';
      }
      if ($i == $num_items) {
        $attributes['class'][] = 'last';
      }
      $output .= '<li' . new Attribute($attributes) . '>' . $item . '</li>';
    }
    $output .= "</{$type}>";
  }

  // Only output the list container and title, if there are any list items.
  // Check to see whether the block title exists before adding a header.
  // Empty headers are not semantic and present accessibility challenges.
  if ($output !== '') {
    if ($title !== '') {
      $title = '<h3>' . $title . '</h3>';
    }
    $output = '<div class="item-list">' . $title . $output . '</div>';
  }
  return $output;
}