Add newlines to theme_item_list

Last modified: January 15, 2008 - 12:07

I wanted to display Who's Online block as an inline, comma separated list using css.

theme_item_list generates markup like this:

<ul><li></li><li></li></ul>

A browser quirk means that due to the lack of whitespace, it won't wrap if you use display: inline;.

But if you have markup like this it wraps fine:

<ul>
<li></li>
<li></li>
</ul>

To add the new line, you'll need to override theme_item_list in your theme's template.php file, then change:

$output .= '<li'. drupal_attributes($attributes) .'>'. $data .'</li>';

to
$output .= '<li'. drupal_attributes($attributes) .'>'. $data .'</li>' ."\n";

You'll then see the line breaks in your generated html, inline lists will wrap, and all will be right in the world once more.

 
 

Drupal is a registered trademark of Dries Buytaert.