We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35756
    • 166 Posts
    profilneurotiker Reply #1, 10 years ago
    Hi there!

    I'm using this getPage-call:

    [[!getPage?
    &elementClass=`modSnippet`
    &element=`getResources`
    &parents=`93`
    &idx=`1`
    &limit=`2`
    &pageVarKey=`page`
    &sortby=`RAND()`
    &includeTVs=`1`
    &includeContent=`1`
    &showHidden=`1`
    &tpl=`NEWS`
    ]]


    As you see there only get two resources listed because of the limit-value.

    I'm using infinite-scroll to show the next two resources aso for more resources...this works well!

    BUT, each time I press the "show more"-link to get the next two resources, the [[+idx]]-value gets counted from "1" again (so 3rd resource has an idx-value of "1" again, 4th resource has an idx-value of "2" again), even if "1" and "2" got used for the first resources that got displayed on page load.

    Is it possible to make the idx-value increasing each time I'm using the ajax-trigger?



    EDIT: because the forum-software did delete the "[[+idx]]" in the title [ed. note: profilneurotiker last edited this post 10 years ago.]
      • 4172
      • 5,888 Posts
      try this:

      [[!getPage?
      &elementClass=`modSnippet`
      &element=`getResources`
      &parents=`93`
      &idx=`[[!getIdx]]`
      &limit=`2`
      &pageVarKey=`page`
      &sortby=`RAND()`
      &includeTVs=`1`
      &includeContent=`1`
      &showHidden=`1`
      &tpl=`NEWS`
      ]]


      snippet 'getIdx':

      $page = $modx->getOption('page',$_REQUEST,1);
      return $page*2-1;
      


      not sure, if &sortby=`RAND()` is a good idea here
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 35756
        • 166 Posts
        Hello again Bruno!

        And thx for the help once more! Sure, the "Rand()" was only for getting different results for testing purposes, but I think too this might be "confusing" (but a test showd me it works too).

        So to start with the result of I, when I choose another value vor the "limit", I have to choose the limit-value as the multiplication-amount minus "limit-value minus 1"...

        Now I'm asking myself if it's possible to look for the parent inbetween the snippet and only "create" the idx-value for all resources that are inside the parent 4 for example. Or the "chunkname" would be useful too, as I use the &tplCondition and &conditionalTpls-function inside my getPage-call.

        I found this:

        /* ***************************************** */
        /* CHUNKS */
        /* ***************************************** */
         
        /* get simple chunk */
        $modx->getChunk('ChunkName');
         
        /* parse a chunk many times */
        foreach ($docs as $doc) {
        $output .= $modx->getChunk('teaserTpl', $doc->toArray() );
        }
        return $output;


        but I'm still trying to sort out how it's used and how i might be able to combine this with the snippet-code you provided wink

        So thanks a lot again to you so far!