I’m trying to create a list of items for a dropdown filter. So after using a series of pdoResources, getImageIists and other snippets to get the finalized output of available data, I have an output that looks something like this: Admission|Second Admission|Admission, 3| and so on (a few hundred results). I specifically divided them by pipes because some results have commas in them.
I then added a snippet to my original pdoResources placeholder like this: [[+listItems:removeDupsList]] to visually check my output for errors.
Here is what I did for my snippet:
<?php
$list = explode('|', $input);
foreach ($list as $x => $value) :
echo "$value<br>";
endforeach;
This gave me my main list. To remove duplicates, I tried this:
<?php
$list_input = explode('|', $input);
$list = array_unique($list_input);
foreach ($list as $x => $value) :
echo "$value<br>";
endforeach;
This resulted in some duplicates being removed, but not all and I cannot figure out why. I even tried using my snippet without any html in it like one article suggested:
$list_input = explode('|', $input);
$list = array_unique($list_input);
foreach ($list as $x => $value) :
$output = $modx->getChunk('list-itemTpl',array(
'myItem' => $value,
));
return $output;
endforeach;
And the list-itemTpl contains this line, but resulted in only the first item:
<p>[[+myItem]]</p>
Any help would be appreciated. Is there a better way of doing this? Thanks.