-
- 25 Posts
I am attempting to use Ditto to wrap a bunch of content around a center image. I have it working using &start to show the first seven across the top, four down each side and the rest across the bottom with four ditto calls. The problem I run into is the orderBy (or sortBy) parameter doesn’t appear to function when start is added, it always sorts by the date the resource was added even though I want it to use menuindex. Short of hacking the snippet does anyone have any ideas?
Try using &offset instead of &start. In the code that seems to be used when preparing the list for display, although the documentation I have suggests it’s been deprecated. The &start parameter seems mostly to be used in pagination, at least from what I’m seeing in the code itself.
switch($orderBy['parsed'][0][1]) {
case "DESC":
$stop = ($ditto->prefetch === false) ? $stop + $start + $offset : $stop + $offset;
$start += $offset;
break;
case "ASC":
$start += $offset;
$stop += $start;
break;
}
-
- 25 Posts
Thanks for the suggestion, unfortunately it doesn’t work. Offset seems to be set from start in the snippet
$offset = isset($start) ? $start : 0;
Maybe I am going about this the wrong way, maybe I should use &save in a single ditto call and then use a separate snippet to display the appropriate portions of the saved result.
I just don’t know. Looking at the code, it should work. But I haven’t actually set up an installation to check it out.
-
- 25 Posts
Unless I’m reading it wrong $offest is set to 0 unless $start is set. I never use that shorthand though so I may be wrong. Anyway for the benefit of others, I did solve the problem by saving the entire result (&save=`3`) and using a snippet with array_slice and $modx->parseChunk to do the same thing. It worked like a charm I think.
$results=$modx->getPlaceholder(’buttons_ditto_resource’);
$output = array_slice($results, $start, $num);
foreach($output as $key=>$value)
{
$code.=$modx->parseChunk(’listTpl’,$value,’[+’,’+]’);
}
return $code;