function theming_example_list_page in Examples for Developers 7
The list page callback.
An example page where the output is supplied as an array which is themed into a list and styled with css.
In this case we'll use the core-provided theme_item_list as a #theme_wrapper. Any theme need only override theme_item_list to change the behavior.
Related topics
1 string reference to 'theming_example_list_page'
- theming_example_menu in theming_example/
theming_example.module - Implements hook_menu().
File
- theming_example/
theming_example.module, line 170 - Explains how a module declares theme functions, preprocess functions, and templates.
Code
function theming_example_list_page() {
$items = array(
t('First item'),
t('Second item'),
t('Third item'),
t('Fourth item'),
);
// First we'll create a render array that simply uses theme_item_list.
$title = t("A list returned to be rendered using theme('item_list')");
$build['render_version'] = array(
// We use #theme here instead of #theme_wrappers because theme_item_list()
// is the classic type of theme function that does not just assume a
// render array, but instead has its own properties (#type, #title, #items).
'#theme' => 'item_list',
// '#type' => 'ul', // The default type is 'ul'
// We can easily make sure that a css or js file is present using #attached.
'#attached' => array(
'css' => array(
drupal_get_path('module', 'theming_example') . '/theming_example.css',
),
),
'#title' => $title,
'#items' => $items,
'#attributes' => array(
'class' => array(
'render-version-list',
),
),
);
// Now we'll create a render array which uses our own list formatter,
// theme('theming_example_list').
$title = t("The same list rendered by theme('theming_example_list')");
$build['our_theme_function'] = array(
'#theme' => 'theming_example_list',
'#attached' => array(
'css' => array(
drupal_get_path('module', 'theming_example') . '/theming_example.css',
),
),
'#title' => $title,
'#items' => $items,
);
return $build;
}