Thanks Lucas
I have a custom table (Members) that I would like to output with a custom snippet (ShowMembersPages) and getPage. This should be quite simple but I cannot see the forest for the trees here!
My original snippet which gets the data from the Members table using xpdo looks like this.
$csaac = $modx->getCollection('Members');
foreach($csaac as $member) {
$output .= '<p>' . $member->get('ID').': '. $member->get('MemberName').' '.$member->get('Surname'). '</p>';
}
return $output;
And gives me the output I want to see:
1: Kazi Khairul Alam
2: Lee-Anne Alde
3: Harold Armstrong
4: Mansour Asgahari
5: Doug Ashton
6: Shirley Baraniski
But how do I do this using getPage? I have revised my snippet as shown by Mark Hamstra etal Preparing custom snippets for pagination with getPage
http://www.markhamstra.com/modx-blog/2011/12/preparing-custom-snippets-for-getpage/ to look like this
$tpl = $modx->getOption('tpl', $scriptProperties, '');
$limit = $modx->getOption('limit',$scriptProperties,6);
$offset = $modx->getOption('offset',$scriptProperties,0);
$addToOffset = $modx->getOption('addToOffset',$scriptProperties,0);
$offset = $offset + $addToOffset;
$c = $modx->newQuery('Members');
$total = $modx->getCount('Members',$c);
echo $total;
$total = $total - $addToOffset;
$total = $total < 0 ? 0 : $total;
$totalVar = $modx->getOption('totalVar', $scriptProperties, 'total');
$modx->setPlaceholder($totalVar,$total);
$c->limit($limit,$offset);
// echo "Found {$total} CSAAC members.";
$collection = $modx->getCollection('Members',$c);
foreach($collection as $item) {
$vars = $item->toArray();
$out[] = $modx->getChunk($tpl, $vars);
}
return implode("\n", $out);
It is here that things begin to fall apart for me. How to I configure the call to getPage to output my data correctly?
I have tried using various examples such as this on the forum to no avail.
[[!getPage?
&elementClass='modSnippet'
&element='ShowMembersPages'
&totalVar='total'
&tpl=`PagedMembers`
]]
<div class="paging">
<ul class="pageList">
[[!+page.nav]]
</ul>
</div>
I think my problem rests in my waking up to how to move the array $vars into a tpl chunk to give the output as in the original unpaginated query. Hope you can give me a nudge and help me see the preoblem.
Thanks
Thanks