This is a very simple snippet to generate ul, ol or dl list from a chunk, each text line of the chunk are put in a ul, ol or dl list.
<?php
/*
Author: Soda
Date 20/11/2007
Purpose: produce html list from chunk (each line = one item)
Parameters :
source: name of the chunk (each line = one item) empty lines are stripped
type: type of the list : ul, ol, dl or none
contclass: class of the list container
delimiter: text to insert between item
*/
$cont=$type?$type:'ul';
$class=$contclass?' class="'.$contclass.'" ':'';
$item=($cont=='dl')?'dd':'li';
$html=$modx->getchunk($source);
$thtml=explode("\n",$html);
$start_cont="\n".'<'.$cont.$class.'>'."\n";
$end_cont='</'.$cont.'>'."\n";
$start_item=' <'.$item.'>';
$end_item='</'.$item.'>'."\n";
$delimiter=htmlentities($delimiter);
if ($type=='none') $start_cont=$end_cont=$start_item=$end_item='';
echo $start_cont;
foreach ($thtml as $line){
$line=trim($line);
if ($line) $vthtml[]=$line;
}
$size = count($vthtml);
for ($i = 0; $i < $size; $i++) {
if ($i == ($size-1)) $delimiter='';
//if ($line)
echo $start_item.$vthtml[$i].$delimiter.$end_item;
}
echo $end_cont;
?>