We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10226
    • 412 Posts
    I’m not supercoder jones so this may be not as good as it could be, but it works great.

    Why did I make this mod? I wanted to automagically wrap the chunks in certain divs with consistency.

    What does it do? Assigns different css classes to the chunks based on the chunk position.

    What does it not do? Laundry, cooking, debugging... I removed the original support for a wrapper div, this can easily be added back with 2 lines of code. I have never used that feature anyway.

    You can tweak it a bit, if you have more than 99 chunks, you will need to up the number a bit. Also the if ($ic == 1) can be modified to give the desired div for a single chunk scenario. I almost added randomize & keep first default chunk options (so if you do randomize, the first chunk is still first). If you have more than 4-5 chunks on most pages you can add a few more cases...

    Drop-In replacement for [[chunkListParser]]
    <?php
    $ar_chunks = split(',',$chunks);
    $ar_chunks = array_unique($ar_chunks);
    $preput = array();
    foreach ($ar_chunks as $chunk) {
    	if ($chunk != '') {
    		$c = $modx->getChunk($chunk);
    		if ($c) {array_push($preput,$c);}
    	}
    }
    $output = array();
    $ic = count($preput);
    $i = 0;
    while ( $item = array_shift( $preput ) )
    {
    $i = $i + 1;
    if ($i == $ic) {$i=99;}
    if ($ic == 1) {$i=99;}
    switch ($i)
    {
    	case 1:
    	$class    = 'sb-first';
    	break;
    
    	case 99:
    	$class = 'sb-last';
    	break;
    
    	default:
    	$class = 'sb-mid';
    }
    $output[] = '<div class="' . $class . '">' . $item . '</div><br/>';
    }
    $output = implode( "\n", $output );
    return $output; 
    ?>


    Mods and comments welcome.

    Thanks!