Render the nth selected option in a listbox


This has stumped me.
I have a listbox(multiselect), how do I render them out and count the nth one to add a closing DIV.
Currently [[*mytv]] outputs over eleven chunks wrapped in HTML.
on the third one I would like to close (bootstrap) ROW DIV and start a new one.

I am well aware of how to do this with GetResources and MIGX across multiple resources but can’t work out how you do it on a single resource.

Ideally I don’t want to have to retrospectively change the TV to a MIGX as that is quite a few pages.

Many thanks


MODX 2.8…

You could write a custom output filter for this.

Make sure the “Output Options” of your TV are defined like this: “Output Type” = Delimiter, “Delimiter:” = || (or alternatively “Output Type” = String).
Add the output modifier to the TV in the template [[*myTV:myListboxOutputFilter]] and create a new snippet “myListboxOutputFilter” with code similar to this:

$arr = explode('||',$input);
$output = '';
for ($i = 0; $i < count($arr); $i++) {
    $output .= $arr[$i];
    if (($i % 3 == 2) && ($i != count($arr) - 1)){
        $output .= '</div><div>';
return $output;

Wow thanks thats perfect…