7 June 2013

This snippets shows you how to create lists the right way using theme_item_list.

Source code viewer
  1. $items = array(
  2. 'Text in item list',
  3. l(t('Link in list'), '<front>')
  4. );
  5.  
  6. $variables['#theme'] = 'item_list';
  7. $variables['#type'] = 'ul';
  8. $variables['#items'] = $items;
  9. echo render($variables);
  10.  
  11. /*
  12.  * Parameters:
  13.  *
  14.  * items: An array of items to be displayed in the list. If an item is a string, then it is used as is. If an item is an array, then the "data" element of the array is used as the contents of the list item. If an item is an array with a "children" element, those children are displayed in a nested list. All other elements are treated as attributes of the list item element.
  15.  * title: The title of the list.
  16.  * type: The type of list to return (e.g. "ul", "ol").
  17.  * attributes: The attributes applied to the list element.
  18.  *
  19.  * For further reference: https://api.drupal.org/api/drupal/includes!theme.inc/function/theme_item_list/7
  20.  */
Programming Language: PHP