theme('item_list')
(or the theme_item_list()
function, as it is currently implemented) has a new feature: You can pass in variable 'empty'
with a string or render array value, and if there are no list items, this value will be output. This is similar to the 'empty'
variable in theme('table')
.
Simple example using a string as the empty value:
$build['foo'] = array(
'#theme' => 'item_list',
'#items' => $results,
'#empty' => t('There were no results. Try a less restrictive filter.'),
'#title' => t('Search Results'),
'#type' => 'ol',
);
Alternative example using a render array as the empty value:
$build['foo'] = array(
'#theme' => 'item_list',
'#items' => $results,
'#empty' => array(
'#type' => 'markup',
'#markup' => t('There were no results. Try a less restrictive filter.'),
),
'#title' => t('Search Results'),
'#type' => 'ol',
);
Introduced in branch:
1.x
Introduced in version:
1.21.0
Impacts:
Module developers
Theme developers
Related Github Issues: