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

    this getPage call
    [[!getPage@fooPropertySet? 
    	&element=`migxLoopCollection` 
    	&packageName=`foo` 
    	&classname=`Foo` 
    	&tpl=`theRowTpl`
    	&limit=`20`
    	&totalVar=`itemsTotal`
    ]]
    allows to output the total number of items using the tag [[+itemsTotal]].
    But in case there are no items found, instead of 0 the output is empty.

    Trying the output filter
    [[+itemsTotal:is=``:then=`0`]]
    I always get the output 0, whatever be the value.

    What am I missing?


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

      • 4172
      • 5,888 Posts
      I think it has to do with the parsing-order of the uncached getPage - call and when the output-filter is parsed.

      You might try another uncached snippet:

      [[!getIntPlaceholder? &placeholder=`itemsTotal`]]


      return (int) $modx->getPlaceholder($placeholder);


      does this work?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 22427
        • 793 Posts
        No, this always results in 0, too.
        Omitting the type casting (int), the result is empty (whatever the number of items found).
          • 4172
          • 5,888 Posts
          was trying this:

          [[!getPage?
          &element=`migxLoopCollection`
          &classname=`modResource`
          &limit=`20`
          &totalVar=`itemsTotal`
          &tpl=`@CODE:[[+pagetitle]]<br>`
          &where=`{"parent":"99999"}`
          ]]
          
          [[+itemsTotal]]
          


          and get as result 0, which is correct.

          without the &where, I get the correct number of resources, too.
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 22427
            • 793 Posts
            I should have mentioned that my &classname=`Foo` refers to a CMP table, so it's not modResource.

            This all worked very well, I just wanted to replace the empty result of [[+itemsTotal]] by the number 0, in case.

            Testing around, I removed the @fooPropertySet reference from the getPage call, resulting in the snippet not being rendered at all.
            (That fooPropertySet is nothing special, just a copy of the default property set for modifications in the future.) Why does this happen?

            And now a real disaster: putting it back (exactly how it was before), nothing changes: getPage is not rendered anymore!
            What the hell is going on here?

              • 4172
              • 5,888 Posts
              modResource or another table. This shouldn't make any difference.
              I get allways the number 0, if no results.

              Are you sure, you have the snippet-call exactly as it was before and you didn't change anything else?
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 22427
                • 793 Posts
                To repair my disaster I had to restore the database from a backup.

                Now only when I omit the property &totalVar=`itemsTotal` from the getPage call, I get back the rendered output like before.

                Including this property to the call however results in the following message:
                Fatal error: Call to undefined function getpage_buildControls() in /www/htdocs/########/#####.de/core/cache/includes/elements/modsnippet/112.include.cache.php on line 88
                This is the code around line 88:
                    if (empty($properties[$properties['totalVar']]) || empty($properties['actualLimit']) || $properties[$properties['totalVar']] <= $properties['actualLimit'] || ($properties['page'] == 1 && $properties[$properties['totalVar']] <= $properties['pageOneLimit'])) {
                        $properties['page'] = 1;
                    } else {
                        $pageNav = getpage_buildControls($modx, $properties);
                        $properties[$properties['pageNavVar']] = $modx->newObject('modChunk')->process(array_merge($properties, $pageNav), $properties['pageNavOuterTpl']);
                        if ($properties['page'] > 1) {
                            $qs[$properties['pageVarKey']] = $properties['page'];
                        }
                    }
                
                So why this function is undefined?
                • discuss.answer
                  • 4172
                  • 5,888 Posts
                  Sounds like there is more corrupted than just the database.
                  Does this file exist?

                  https://github.com/opengeek/getPage/blob/master/core/components/getpage/include.getpage.php
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 22427
                    • 793 Posts
                    Thank you, Bruno - indeed the whole getPage folder was missing in core/components/. I should have restored the files from the backup, too.

                    But there remains the mystery how it could disappear.
                    The only action I performed these days was deleting the Articles Extra. Is it imaginable that this was deleting getPage too?
                    (If so, there should be a warning of such an unwanted side effect.)
                      • 4172
                      • 5,888 Posts
                      I think getPage is included within articles.
                      So, if you delete the articles-extra, this might also delete the extras which are included with the articles-package.
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!