We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19534
    • 183 Posts
    Hey!

    Is it somehow possible to use getPage and SimpleSearch? I’ve already setup some templates for getPage. I don’t want to create new chunks for every snippet providing pagination.

    By the way: Why are so many Snippets providing there own pagination? I think pagination should always provide the same look and feel on a website. But with all the different paginations provided by common snippets this is not always possible: For example without modification of SimpleSearch it is not possible to create a pagination like this:

    < prev ... 4 | 5 | 6 | 7 ... next >

    What do you think?
      Add-On to easily manage your multilingual sites: Babel
      • 1778
      • 659 Posts
      Hello

      You can create a "standard" pagination chunk, and use it in your different snippets...

        • 19534
        • 183 Posts
        Hey anso!

        Of course I can do this. But this requires that all snippets using this chunk must provide the some placeholders etc. And I think this is not case because every snippet handles pagination in the way the author thought it would be the best way. Using getPage seems to me more sensible: Authors of snippets supporting pagination don’t have to implement their own pagination logic and snippet users can reuse their getPage snippet calls everywhere.
          Add-On to easily manage your multilingual sites: Babel
          • 1778
          • 659 Posts
          What snippets are you talking about ?
          In Revo, I guess getPage is THE snippet required to put pagination. It works with all snippets that return limitable collections... So one chunk is enough...
          Maybe I’m wrong on this, or you have specific needs in mind?
          Cheers
            • 19534
            • 183 Posts
            I’m using getResource (with getPage like described in the docu), SimpleSearch (-> I created this post to aks if I can use getPage with SimpleSearch), Quip (don’t know if it’s compatible with getPage)...

            Except of getResource there are no hints in the docs that getPage can be used. For example in the SimpleSearch doc there are only information about using the SimpleSearch built-in pagination.

            I’ll simple try to use getPage for these snippets and post if it works. But when getPage is supported by them why do all these snippets provide their own pagination?
              Add-On to easily manage your multilingual sites: Babel
              • 1778
              • 659 Posts
              I didn’t try that
              [[!getPage?
                 &elementClass=`modSnippet`
                 &element=`SimpleSearch`
              
                 &parents=`17`
                 &depth=`2`
                 &limit=`10`
                 &pageVarKey=`page`
              
                 &includeTVs=`1`
                 &includeContent=`1`
              
                 &tpl=`yourResultsTpl`
              ]]
              <div class="paging">
              <ul class="pageList">
                [[!+page.nav]]
              </ul>
              </div>
              


              I suppose it should work but no time to test at this time, I’m dealing with a 3PC...


              But when getPage is supported by them why do all these snippets provide their own pagination?
              I suppose the snippets are created with in mind the idea that user don’t have getPage installed... BTW pagination is not a ’must have’ for everyone...
              Cheers
                • 10985
                • 3 Posts
                Did the above work? I tried it and it did not. I think it is because SimpleSearch does not use the same ’limit’ and ’offset’ parameters that getPage expects. Any ideas?
                  • 42712
                  • 4 Posts
                  Hi!...Excuse me by post in this thread but I was having the same goal trying get work Simplesearch plugin with getPage in Modx Revo 2.2.6 ... and after search some hours and losing almost all day without luck...I achieve that goal....so I think could be useful for someone else share my solution...so...I found very useful the article of Mark Hamstra(https://www.markhamstra.com/modx-blog/2011/12/preparing-custom-snippets-for-getpage/)...in that article he explain how to get working getPage plugin Add-on with another plugins...
                  So...I achieve this in some simple steps:

                  1. I edited the snippet Simplesearch in the section /* iterate through search results */ and added the lines 4 and 5 like this:
                  
                  ....code...
                  if (!empty($response['results'])) {
                      /* iterate through search results */
                    $totalVar = $modx->getOption('totalVar', $scriptProperties, 'total');
                    $modx->setPlaceholder($totalVar,$response['total']);
                    foreach ($response['results'] as $resourceArray) {
                          $resourceArray['idx'] = $idx;
                        
                  ...code...
                  


                  2. Then I edited the file "modx_root/core/components/simplesearch/model/simplesearch/driver/simplesearchdriverbasic.class.php" in the search function, about the line 200 as:
                  ...code....
                  if (!empty($perPage)) {
                              $limit = $this->modx->getOption('limit',$scriptProperties,10);
                  // here we use the options for getPage plugin instead default simplesearch pagination...
                  			$offset = $this->modx->getOption('offset',$scriptProperties,0);
                  			$c->limit($limit,$offset);
                              /*$offset = $this->modx->getOption('start',$this->config,0);
                              $offsetIndex = $this->modx->getOption('offsetIndex',$this->config,'sisea_offset');
                              if (isset($_REQUEST[$offsetIndex])) $offset = (int)$_REQUEST[$offsetIndex];
                              $c->limit($perPage,$offset);*/
                      	}
                  ...code....
                  


                  3. Almost done...finally I made the call for getPage snippet in the template:
                  ...code...
                  [[!getPage? &element=`SimpleSearch` &elementClass=`modSnippet` &ids=`14,15,16,10` &exclude=`1,2,6,29,47,10,14,15,16` &idType=`parents` &tpl=`result_item` &containerTpl=`container_results` &highlightResults=`0` &limit=`3` &offset=`0`]]
                  ..code..
                  <div class="pageNav">[[!+page.nav]]</div>
                  


                  And that was all...These lines should be modified because getPage works with different variable names of "offset" and "limit" and never knows the total of results to paginate if we dont tell him...I hope it will be helpful for someone because I didn't find any solution like this on the web...also...excuse me english at some point because I don't speak very well....
                    • 37012
                    • 32 Posts
                    Hi ijmorgado,

                    I tried your solution, but it did not display the same search results on me(I got doubles). I've found SimpleSearch to be customizable enough for me though.
                      • 3908
                      • 6 Posts
                      Quote from: ijmorgado at Feb 03, 2013, 11:22 PM
                      Hi!...Excuse me by post in this thread but I was having the same goal trying get work Simplesearch plugin with getPage in Modx Revo 2.2.6 ... and after search some hours and losing almost all day without luck...I achieve that goal....so I think could be useful for someone else share my solution...so...I found very useful the article of Mark Hamstra(https://www.markhamstra.com/modx-blog/2011/12/preparing-custom-snippets-for-getpage/)...in that article he explain how to get working getPage plugin Add-on with another plugins...
                      So...I achieve this in some simple steps:

                      1. I edited the snippet Simplesearch in the section /* iterate through search results */ and added the lines 4 and 5 like this:
                      
                      ....code...
                      if (!empty($response['results'])) {
                          /* iterate through search results */
                        $totalVar = $modx->getOption('totalVar', $scriptProperties, 'total');
                        $modx->setPlaceholder($totalVar,$response['total']);
                        foreach ($response['results'] as $resourceArray) {
                              $resourceArray['idx'] = $idx;
                            
                      ...code...
                      


                      2. Then I edited the file "modx_root/core/components/simplesearch/model/simplesearch/driver/simplesearchdriverbasic.class.php" in the search function, about the line 200 as:
                      ...code....
                      if (!empty($perPage)) {
                                  $limit = $this->modx->getOption('limit',$scriptProperties,10);
                      // here we use the options for getPage plugin instead default simplesearch pagination...
                      			$offset = $this->modx->getOption('offset',$scriptProperties,0);
                      			$c->limit($limit,$offset);
                                  /*$offset = $this->modx->getOption('start',$this->config,0);
                                  $offsetIndex = $this->modx->getOption('offsetIndex',$this->config,'sisea_offset');
                                  if (isset($_REQUEST[$offsetIndex])) $offset = (int)$_REQUEST[$offsetIndex];
                                  $c->limit($perPage,$offset);*/
                          	}
                      ...code....
                      


                      3. Almost done...finally I made the call for getPage snippet in the template:
                      ...code...
                      [[!getPage? &element=`SimpleSearch` &elementClass=`modSnippet` &ids=`14,15,16,10` &exclude=`1,2,6,29,47,10,14,15,16` &idType=`parents` &tpl=`result_item` &containerTpl=`container_results` &highlightResults=`0` &limit=`3` &offset=`0`]]
                      ..code..
                      <div class="pageNav">[[!+page.nav]]</div>
                      


                      And that was all...These lines should be modified because getPage works with different variable names of "offset" and "limit" and never knows the total of results to paginate if we dont tell him...I hope it will be helpful for someone because I didn't find any solution like this on the web...also...excuse me english at some point because I don't speak very well....

                      Hi ijmorgado,

                      I came across the same issue and tried your solution...

                      It works pretty well, thanks a lot!