We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17838
    • 82 Posts
    Hello,

    Could anyone give me an example of getPage snippet usage?

    --
    Regards
    MM
      • 26903
      • 1,336 Posts
      There’s a usage example with the getResources snippet, have a look here :-

      http://svn.modxcms.com/docs/display/ADDON/getresources#getResources-UsinggetPageforPagination
        Use MODx, or the cat gets it!
        • 17838
        • 82 Posts
        Thanks for the example.

        So what kind of data should mySnippet return to getPage to make it work?
        When calling getPage snippet I can pass parameters to mySnippet, can I?

        --
        Regards
        MM
          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: maciej.m at Feb 28, 2010, 06:57 AM

          So what kind of data should mySnippet return to getPage to make it work?
          Your snippet needs to accept &limit and &offset properties, and also needs to set a placeholder (’total’ by default, but you can specify the name of the placeholder with the &totalVar property) with an integer indicating the total number of records for the paging. Your snippet sets the placeholders and deals with rendering whatever it is meant to render based on limit and offset.

          Quote from: maciej.m at Feb 28, 2010, 06:57 AM

          When calling getPage snippet I can pass parameters to mySnippet, can I?
          All properties passed to getPage will be passed down into your Snippet automatically, so take all the properties you would set on your Snippet and put them on your getPage call (or propertyset).
            • 17838
            • 82 Posts
            Ok, by calling getPage i get results I would normally get with mySnippet (here NLListFiles), but I don’t get any pagination.

            [[!getPage?
            &elementClass=`modSnippet`
            &element=`NLListFiles`
            &limit = `5`
            &totalVar = `total`
            ]]


            In my snippet
            $filelist = new NLListFiles ($modx, array('limit'=>$scriptProperties['limit'], 'offset' => $scriptProperties['offset']));
            $modx->setPlaceholder('total',$filelist->allRecordsNum); // printing allRecordsNum gives me 7
            echo $filelist->printData();


            So my snippet renders 5 elements and sets allRecordsNum to 7 for all records that satisfy criteria.
            Is there something I’m missing?
              • 17838
              • 82 Posts
              Ok, I get it now.
              I had only to put [[!+page.nav]] placeholder

              The only problem is that paging doesn’t append my $_GET variables.
                • 17838
                • 82 Posts
                So I have 2 problems with the snippet:

                1. It doesn’t append my query string (f.e. /?id=2&view=6)
                I get (/?id=2&page=n) in navigation links
                2. Navigation disapears upon refreshing browser
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Your offset cannot be set in the snippet properties; it has to be determined from the paging.

                  If by GET variables you mean view is supposed to indicate the page number, then you need a pageVarKey property set to view; otherwise it uses page as pageVarKey by default.
                    • 17838
                    • 82 Posts
                    I understand, but I didn’t set offset in snippet properties. ’view’ parameter was to to different things than ’paging’.
                      • 22303 MODX Staff
                      • 10,725 Posts
                      Quote from: maciej.m at Mar 01, 2010, 11:43 AM

                      I understand, but I didn’t set offset in snippet properties. ’view’ parameter was to to different things than ’paging’.
                      Oh I see; it doesn’t currently automatically preserve your additional query string parameters; you can:

                      a) use a Snippet to set the qs property on the getPage snippet, i.e. &qs=`[[!appendQueryString]]`, OR
                      b) update to latest SVN (branches/2.0@6422 or later) and install getPages-1.0.0-beta2 which I just uploaded to address this problem

                      I have created a few new core enhancements to help all component developers deal with these issues more easily:

                      [*] Added modX::toQueryString() static method to easily turn an associative array into a valid query string.
                      [*] modX::makeUrl() and modContext::makeUrl() now accept an array or string as the third parameter for query string parameters and converts an array using modX::toQueryString().
                      [*] Added modRequest::getParameters() to get a single or an array of GPC values, automatically excluding the MODx reserved $_GET parameters. By default it will get all $_GET parameters except the reserved ones, but you can also specify the parameter( s ) to get as well as the type of GPC variables to get them from, i.e. GET, POST, COOKIE or REQUEST.

                      Let me know if you have any additional questions regarding appending query string parameters to the paging links.

                      Quote from: maciej.m at Feb 28, 2010, 05:32 PM

                      2. Navigation disapears upon refreshing browser
                      I cannot reproduce this behavior, at least not with getpage-1.0.0-beta2. Can you post the content of the Resource containing the call to getPage? Maybe I can determine some other cause...