We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Dear MODX people,

    I needed to create an image slider that simply grabs all images from one folder and displays them. So I went with Foundation, Orbit and the MODX extra FileLister.

    The only thing I was missing was: an index for the single files that FileLister found.

    Working a lot with getResources, i was used to have [[$idx]] available for each single item the extra had in its output.

    If you open the FileLister Snippet and search for
    unset($directory);
    you find the important lock next to it.

    Just edit as this and you have the [[$idx]] counter available as a placeholder.
    foreach ($files as $file) {
        $odd = $i % 2;
        $file['cls'] = $odd ? $altCls : $cls;
        $file['idx'] = $i;                /* this line is new */
        if ($i == 0) $file['cls'] .= ' '.$firstCls;
        if ($i == ($totalCount-1)) $file['cls'] .= ' '.$lastCls;
    	
        $list[] = $fileLister->getChunk($fileTpl,$file);
        $i++;
    }
    unset($file);


    Now, you can use it in your snippets like this:
    <button data-slide="[[+idx]]" [[+idx:is=`0`:then=`class="is-active"`]]><span class="show-for-sr">Image no. [[+idx]] slide details.</span></button>


    Cheers

    Guido