We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33238
    • 388 Posts
    Hello everyone
    I'm working inside MigX.

    [[+date:strtotime]] (this is a date field MigX, the client pick the event date, result example: 1481885100)
    [[!getDate`]] (This is an extra that is showing the date from today, right now is displaying: 1481716408)

    How can I compare this two fields to hide or show content?
    I need to tell MigX, hide "this code" if the client date ( [[+date:strtotime]] ) is less or equal to today for example.

    I tried something like this :
    [[+date:strtotime:lessthanorequalto=`[[!getDate]]`:then=`Hide`:else=`Show`]]

    but the result is always the same result no mater if the date is higher or lower.

    Thank you very much for any help.
    Cheers. [ed. note: Ysanmiguel last edited this post 9 years, 10 months ago.]
      --
      ysanmiguel.com
      • 3749
      • 24,544 Posts
      First, put this on your page to see if your date placeholder with the modifier actually returns a timestamp rather than a human readable date:

      <p>DATE: [[+date:strtotime]]</p>



      I think that the getDate snippet is overkill for your use, since you just want a timestamp.

      Assuming that the test above comes out OK, I think the real problem is that calling getDate uncached delays its execution, so it's not available when the modifiers are processed (i.e., the lessthanorequalto modifier is processing the tag, rather than the timestamp). Calling it cached won't help since you won't get the current time except when the cache is cleared.

      I think the best solution is a custom snippet (*much* faster than a series of output modifiers):

      Here's the code (untested):

      [[!DateCheck? &date=`[[+date]]` ]]



      /* DateCheck snippet */
      $date = $modx->getOption('date', $scriptProperties, '');
      if (empty($date)) {
          $output = 'Empty Date';
      } else {
          $dateStamp = strtotime($date);
      
          if ($dateStamp === false) {
              $output = 'Date could not be parsed into a timestamp';
          } else {
              $output = $dateStamp <= time()
              ? 'Show'
              : 'Hide';
          }
      }
      
      return $output;
      


        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting