[drupal-devel] Re: [drupal:dries] /includes theme.inc

Sergio lsmoura at gmail.com
Wed Oct 19 19:58:41 UTC 2005


May I suggest a little bit different?

/**
* Return a themed list of items.
*
* @param $items
* An array of items to be displayed in the list.
* @param $title
* The (optional) title of the list.
* @return
* A string containing the list output.
*/
function theme_item_list($items = array(), $title = NULL, $type =
'unordered list') {
$class = '';
$output = '';

if (isset($items)) {
switch($type) {
case 'unordered list':
case 'ul':
$list .= '<ul>';
foreach ($items as $item) {
$list .= '<li>'. $item .'</li>';
}
$list .= '</ul>';
$class = 'unordered-list';
break;

case 'ordered list':
case 'ol':
$list .= '<ol>';
foreach ($items as $item) {
$list .= '<li>'. $item .'</li>';
}
$list .= '</ol>';
$class = 'ordered-list';
break;

case 'definition list':
case 'dl':
$list .= '<dl>';
foreach ($items as $item) {
$list .= '<dt>'. $item .'</dt>';
}
$list .= '</dl>';
$class = 'definition-list';
break;
}

if (isset($title)) {
$output .= '<h3>'. $title .'</h3>';
}

$output .= '<div class="'. $class .'">'. $list .'</div>';

return $output;
}

Reasons:
* E_ALL Compilant
* break was missing
* good for types 'ul'-like (like I prefer) and 'ordered list'-like (like you
prefer)

btw... shouldnt there be a way to changing the class name? just a tought...

Regards,
- Sergio

On 10/18/05, drupal-devel-owner at drupal.org <drupal-devel-owner at drupal.org>
wrote:
>
> Op 18-okt-2005, om 16:45 heeft drupal-devel at drupal.org het volgende
> geschreven:
> > User: dries Branch: HEAD Date: Tue, 18 Oct 2005 14:45:09 +0000
> >
> > Modified files:
> > /includes theme.inc
> >
> > Log message:
> > - Patch #32573 by Moshe: added support for ordered lists to
> > theme_item_list().
> >
> > Links:
> > http://cvs.drupal.org/diff.php?path=drupal/includes/
> > theme.inc&old=1.261&new=1.262
> >
> > --
> > [ Drupal cvs list | http://list.drupal.org/ ]
> >
> >
>
> I do not, and I repeat _not_ like this approach!
>
> A nicer solution would imo be:
>
> /**
> * Return a themed list of items.
> *
> * @param $items
> * An array of items to be displayed in the list.
> * @param $title
> * The (optional) title of the list.
> * @return
> * A string containing the list output.
> */
> function theme_item_list($items = array(), $title = NULL, $type =
> 'unordered list') {
> $class = str_replace('-', ' ', $type);
>
> if (isset($items)) {
> switch($type) {
> case 'unordered list':
> $list .= '<ul>';
> foreach ($items as $item) {
> $list .= '<li>'. $item .'</li>';
> }
> $list .= '</ul>';
>
> case 'ordered list':
> $list .= '<ol>';
> foreach ($items as $item) {
> $list .= '<li>'. $item .'</li>';
> }
> $list .= '</ol>';
>
> case 'definition list':
> $list .= '<dl>';
> foreach ($items as $item) {
> $list .= '<dt>'. $item .'</dt>';
> }
> $list .= '</dl>';
> }
>
> if (isset($title)) {
> $output .= '<h3>'. $title .'</h3>';
> }
>
> $output .= '<div class="'. $class .'">'. $list .'</div>';
>
> return $output;
> }
>
>
> Isn't something like this nicer? And, easier to use?
>
>
>
>
> Steef
>
> ---
> Stefan Nagtegaal
> Drupal-Devel at iStyledThis.nl
> Drupal Development Mailinglist
>
>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://drupal3.drupal.org/pipermail/development/attachments/20051019/62e8f772/attachment.htm


More information about the drupal-devel mailing list