We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38878
    • 255 Posts
    Im using getPage with a custom snippet and all is working fine. But, I want to output the count of items on the current page. I assumed according to all I have read that the following would work as long as I call my second getCount after the limit/offest call:
    $total = $modx->getCount('myCollections',$c);//<== first getCount for totalVar
    $totalVar = $modx->getOption('totalVar', $scriptProperties, 'total');
    $modx->setPlaceholder($totalVar,$total);
    
    $limit = $modx->getOption('limit',$scriptProperties,5);
    $offset = $modx->getOption('offset',$scriptProperties,0);
    $c->limit($limit,$offset);
    $c->sortby($sortby,$dir);
    
    $pagetotal = $modx->getCount('myCollections',$c);// <== this call equals the same number as the first getCount call above on the first page, and zero on subsequent pages. 
    $modx->setPlaceholder('pagecount',$pagetotal);
    $all_xnippets = $modx->getCollection('myCollections',$c);
    

    Any ideas why this doesn't work? Thx!

    This question has been answered by Bruno17. See the first response.

    • discuss.answer
      • 4172
      • 5,888 Posts
      why not

      $pagetotal = 0;
      if ($all_xnippets = $modx->getCollection('myCollections',$c)){
          $pagetotal = count($all_xsnippets);    
      }
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 38878
        • 255 Posts
        Quote from: Bruno17 at Dec 06, 2015, 11:40 AM
        why not

        $pagetotal = 0;
        if ($all_xnippets = $modx->getCollection('myCollections',$c)){
            $pagetotal = count($all_xsnippets);    
        }

        Yeah Bruno, that worked. I guess I'm just curious why my method didn't after applying the criteria.

        Thx!
          • 38878
          • 255 Posts
          Quote from: harveyev at Dec 06, 2015, 05:00 PM
          Quote from: Bruno17 at Dec 06, 2015, 11:40 AM
          why not

          $pagetotal = 0;
          if ($all_xnippets = $modx->getCollection('myCollections',$c)){
              $pagetotal = count($all_xsnippets);    
          }

          Yeah Bruno, that worked. I guess I'm just curious why my method didn't after applying the criteria.

          Thx!

          Only thing I found is that I need to turn caching OFF in the getPage snippet for this to work when navigating to previous pages.
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            getPage has to be called uncached anyway.

            Do Not Cache
            The getPage snippet must never be called cacheable on a Resource that is cacheable. It is best to always call getPage with the non-cacheable token, !, while still caching the rest of the Resource output. The same rule applies for the placeholder represented by the pageNavVar property (page.nav by default) so that its output is not cached into the cacheable page content.
            https://rtfm.modx.com/extras/revo/getpage#getPage-Usage
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 38878
              • 255 Posts
              Quote from: sottwell at Dec 06, 2015, 05:38 PM
              getPage has to be called uncached anyway.

              Do Not Cache
              The getPage snippet must never be called cacheable on a Resource that is cacheable. It is best to always call getPage with the non-cacheable token, !, while still caching the rest of the Resource output. The same rule applies for the placeholder represented by the pageNavVar property (page.nav by default) so that its output is not cached into the cacheable page content.
              https://rtfm.modx.com/extras/revo/getpage#getPage-Usage

              I was referring to the caching of the snippet content being cached. Getpage itself is called uncached. Setting the caching in getPage properties as I understood from https://rtfm.modx.com/extras/revo/getpage#getPage-CachingProperties caches the result set for the page. That setting causes my counts not to render. Even setting the placeholder to uncached doesn't work [[!+count]]. One would assume that the need to call the [[+page.nav]] uncached also (as stated above) would apply to other placeholders as well. But alas it does not.
                • 18373 ☆ A M B ☆
                • 3,141 Posts
                Quote from: harveyev at Dec 07, 2015, 07:07 AM
                Quote from: sottwell at Dec 06, 2015, 05:38 PM
                getPage has to be called uncached anyway.

                Do Not Cache
                The getPage snippet must never be called cacheable on a Resource that is cacheable. It is best to always call getPage with the non-cacheable token, !, while still caching the rest of the Resource output. The same rule applies for the placeholder represented by the pageNavVar property (page.nav by default) so that its output is not cached into the cacheable page content.
                https://rtfm.modx.com/extras/revo/getpage#getPage-Usage

                I was referring to the caching of the snippet content being cached. Getpage itself is called uncached. Setting the caching in getPage properties as I understood from https://rtfm.modx.com/extras/revo/getpage#getPage-CachingProperties caches the result set for the page. That setting causes my counts not to render. Even setting the placeholder to uncached doesn't work [[!+count]]. One would assume that the need to call the [[+page.nav]] uncached also (as stated above) would apply to other placeholders as well. But alas it does not.

                If getCache uses cached output, your snippet isn't executed and the placeholder isn't set.
                  Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                  Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                  • 38878
                  • 255 Posts
                  Quote from: markh at Dec 07, 2015, 07:47 AM
                  Quote from: harveyev at Dec 07, 2015, 07:07 AM
                  Quote from: sottwell at Dec 06, 2015, 05:38 PM
                  getPage has to be called uncached anyway.

                  Do Not Cache
                  The getPage snippet must never be called cacheable on a Resource that is cacheable. It is best to always call getPage with the non-cacheable token, !, while still caching the rest of the Resource output. The same rule applies for the placeholder represented by the pageNavVar property (page.nav by default) so that its output is not cached into the cacheable page content.
                  https://rtfm.modx.com/extras/revo/getpage#getPage-Usage

                  I was referring to the caching of the snippet content being cached. Getpage itself is called uncached. Setting the caching in getPage properties as I understood from https://rtfm.modx.com/extras/revo/getpage#getPage-CachingProperties caches the result set for the page. That setting causes my counts not to render. Even setting the placeholder to uncached doesn't work [[!+count]]. One would assume that the need to call the [[+page.nav]] uncached also (as stated above) would apply to other placeholders as well. But alas it does not.

                  If getCache uses cached output, your snippet isn't executed and the placeholder isn't set.

                  I guess the difference is that the page.nav and total placeholders are processed by getpage uncached. I guess I'll take a look at getpage and try to hack it to add an itemcount.