We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37143
    • 74 Posts
    Hi everyone, I have a getResources call that comps published date to current date to show a number of new items (less than 14 days old). Custom snippet works fine. Here is my code:

    [[!getResources? &where=`{"publishedon:>=":[[!getCurrentTimeMinus]]}` &parents=`225` &toPlaceholder=`number` &limit=`0` ]]
    <div id="new-videos"><span>[[+total]]</span> New Videos</div>

    I'm not using a tpl, as I just want the total output. The above works.
    HOWEVER, when I try to change it to this:

    [[+total:is=`0`:then=``:else=`<div id="new-videos"><span>[[+total]]</span> New Videos</div>` ]]

    I get no output returned. Can anyone tell me what I am doing wrong? I tried calling [[!+total]] but no luck there.

    Thanks in advance for any help!
      • 4172
      • 5,888 Posts
      Not sure if this will work:

      snippet ifResults:
      <?php
      $results = $modx->runSnippet('getResources',$scriptProperties);
      if (!empty($results)){
          return $then;
      }
      


      [[!ifResults? 
      &where=`{"publishedon:>=":[[!getCurrentTimeMinus]]}` 
      &parents=`225` 
      &limit=`1` 
      &then=`<div id="new-videos"><span>[[+total]]</span> New Videos</div>` ]]
      
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 37143
        • 74 Posts
        Thanks Bruno, that definitely worked. I got my issue sorted by actually setting a tpl with just the [[+total]] in it, then limiting the output to 1 with &limit=`1`. But your limit suggestion below was what triggered this for me, so Thank You!

        BF


        Quote from: Bruno17 at Nov 20, 2013, 03:11 PM
        Not sure if this will work:

        snippet ifResults:
        <!--?php
        $results = $modx--->runSnippet('getResources',$scriptProperties);
        if (!empty($results)){
            return $then;
        }
        


        [[!ifResults? 
        &where=`{"publishedon:>=":[[!getCurrentTimeMinus]]}` 
        &parents=`225` 
        &limit=`1` 
        &then=`<div id="new-videos"><span>[[+total]]</span> New Videos</div>` ]]