I am trying to set up EventsX and I have most things working except pagination. There is no example of pagination in the docs. I thought I could combine with getResources and getPage, but I have had no success. getResources isn’t working for me. I am more of a front end person, so as soon as I start looking at snippets, I’m a bit out of my league. Any help would be greatly appreciated!
Here is my code that outputs but does not paginate:
[[!EventsX? &tpl=`evxEventTpl` &limit=`2`]]
A snippet that works with getPage has to accept the limit and offset properties for limiting the data set, and set a placeholder with the total number of items.
The snippet EventsX only accepts a limit property and doesn’t set the total placeholder. So you have to adjust the code to make it work. Duplicate the snippet EventsX and call it CustomEventsX. Then make these changes according to this post.
//The first 19 lines of the snippet remain unchanged
$c = $modx->newQuery('evxEvent');
$c->andCondition(array('active' => 1, "enddate >= '".date('Y-m-d')."'"));
//These next 5 lines of code is the new stuff
$total = $modx->getCount('evxEvent',$c);
$totalVar = $modx->getOption('totalVar', $scriptProperties, 'total');
$offset = $modx->getOption('offset',$scriptProperties,0);
//delete line 20 = $c->limit($limit);
//keep the rest of the code from line 21 to the end
$events = $modx->getCollection('evxEvent', $c);
Then call getPage with the new snippet:
Wow, it works! I can’t thank you enough! I’ll try to study this… Maybe one day I can get to this level. Cheers!