We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22303 MODX Staff
    • 10,725 Posts
    This is an auto-generated topic for getPage 1.0.0-pl by opengeek.

    Brief Description:

    A generic wrapper snippet for returning paged results and navigation from snippets that return limitable collections.
    getPage 1.0.0-pl (August 18, 2010)

    • Add pageActiveTpl to differentiate current page link
    • Add firstItem and lastItem properties/placeholders
    • Add support for snippets that send output toPlaceholder
      • 29626
      • 34 Posts
      Hello OpenGeek,

      The snippet seems having some trouble with tpl options in snippet call.
      Calling of my custom templates is below (chunks based)
         &pageFirstTpl=`getPageFirstTpl`
         &pageLastTpl=`getPageLastTpl`
         &pagePrevTpl=`getPagePrevTpl`
         &pageNextTpl=`getPageNextTpl`
      

      And each chunk contains only the HTML of the snippet code, without any PHP escaping slashes.

      The output is only giving the chunks names. See testing website.
      Seems the following function of the package doesn’t do its job correctly with chunks.
      It works well with direct HTML inside the snippet call - but not very usefull for every day coding practise.
      function getpage_makeUrl(& $modx, $properties, $pageNo, $tpl) {
          $qs = $properties['qs'];
          $qs[$properties['pageVarKey']] = $pageNo;
          $properties['href'] = $modx->makeUrl($modx->resource->get('id'), '', $qs);
          $properties['pageNo'] = $pageNo;
          $nav= $modx->newObject('modChunk')->process($properties, $tpl);
          return $nav;
      }
      


      [Edit]
      I’ve found a workaround until you have found why it doesn’t do chunk processing, but I don’t know if it is really the good way of doing this...
      $properties['pageFirstTpl'] = empty($pageFirstTpl) ? "<li class=\"control\"><a[[+title]] href=\"[[+href]]\">First</a></li>" : $modx->getChunk($pageFirstTpl);
      $properties['pageLastTpl'] = empty($pageLastTpl) ? "<li class=\"control\"><a[[+title]] href=\"[[+href]]\">Last</a></li>" : $modx->getChunk($pageLastTpl);
      $properties['pagePrevTpl'] = empty($pagePrevTpl) ? "<li class=\"control\"><a[[+title]] href=\"[[+href]]\"><<</a></li>" : $modx->getChunk($pagePrevTpl);
      $properties['pageNextTpl'] = empty($pageNextTpl) ? "<li class=\"control\"><a[[+title]] href=\"[[+href]]\">>></a></li>" : $modx->getChunk($pageNextTpl);
      


      Have a good day!
      Terry.
        • 22303 MODX Staff
        • 10,725 Posts
        At the current time, you have to set the content of these tpl’s in a property set. It would be a good feature request to allow chunks to be specified as well.
          • 29626
          • 34 Posts
          Hi OpenGeek,

          Ok, you could consider it as a feature request (lol)!
          I think I could do that kind of actions with Jira aka submitting "my little patch" using $modx->getChunk($tpl) or a given set for any snippet’s template properties.

          Bye.
            • 22303 MODX Staff
            • 10,725 Posts
            FWIW, bugs and feature requests for getPage go here.
              • 29626
              • 34 Posts
              Hello OpenGeek,

              Quote from: OpenGeek at Sep 16, 2010, 08:50 PM

              FWIW, bugs and feature requests for getPage go here.

              Ok i will use gitHub if you prefer.
              I have already posted on modx Jira two days before today.

              Have a good day!
                • 36834
                • 25 Posts
                Hello

                I am using the getPage snippet with the getResources snippet. When I use the getResources snippet independently, I can set an ’offset’ property to return records from a start point.

                eg: [[getResources? &parents=`2`&includeTVs=`1` &processTVs=`1` &tpl=`newsSummaryTpl` &limit=`5` offset=`3`]]

                When used in conjunction with getPage the offset value is ignored.

                eg: [[!getPage? &elementClass=`modSnippet` &element=`getResources` &parents=`2` &includeTVs=`1` &processTVs=`1` &tpl=`newsSummaryTpl` &limit=`2` &offset=`3`]]

                Is this the expected behaviour? And should I be using a different technique to limit the returned results in this circumstance?

                Thanks in advance.

                Apache 1.3.41
                PHP 5.2.1
                Mysql 5.0.41
                Mysql, Mysqli, Pdo_mysql 5.0.24a

                MODx Revolution 2.0.0-pl rev7212

                Mac OS 10.4.11

                Firefox 3.5.7
                Safari 4.0.3 (4531.9)
                  • 22303 MODX Staff
                  • 10,725 Posts
                  getPage and getResources work together to accomplish paging using offset and limit, so if it didn’t work, everyone would have a problem. Perhaps if you describe exactly what your problem is we can better assist, but it’s not clear to me what it is you are trying to do. Keep in mind, getPage is meant for paging, so the offset is determined automatically based on the current page number. Or maybe I’m missing something.
                    • 36834
                    • 25 Posts
                    Thanks for the reply. I am trying to do the following:

                    I have a latest news section that lists the five latest news articles. I have no problem with this. I use getResources with the following config and all works as expected. I don’t need paging because there is never enough content as I only ever display five articles.

                    [[getResources? &parents=`2`&includeTVs=`1` &processTVs=`1` &tpl=`newsSummaryTpl` &limit=`5`]]

                    I then have a news archive section that displays all the previous articles except the five latest news articles. To omit the five latest news articles using just getResources I would use the following config (which works fine)

                    [[getResources? &parents=`2`&includeTVs=`1` &processTVs=`1` &tpl=`newsSummaryTpl` &offset=`5`]]

                    If I try to use these parameters with getPage the offset parameters (see example config below) appear to have no effect upon the behaviour of the getResources snippet and I get all records returned for paging (the paging works correctly, it just doesn’t prevent the five latest news articles from being included in the results). I guess that this might be because getPage has a parameter of the same name?

                    [[!getPage? &elementClass=`modSnippet` &element=`getResources` &parents=`2` &includeTVs=`1` &processTVs=`1` &tpl=`newsSummaryTpl` &limit=`2` &offset=`5`]]

                    Thanks
                      • 22303 MODX Staff
                      • 10,725 Posts
                      Like I said, getPage automatically determines offset based on the page number so that is not possible with getPage. You need another way to select the top five and isolate them so you don’t need the offset, or you’ll need a new feature in getPage to add x to the offset and subtract it from the total.