We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19975
    • 429 Posts
    I would like to show a content element (within a template) between two dates. I’ve setup two date TVs and a current time/date PHP snippet however I can’t seem to trigger a PHX greater or less than string.

    [+phx:if=`[*myfromDate*]`:gt=`[!currentDateSnippet!]`:then=`{{showChunk}}`+]
    

    Are there any existing snippets available to address my desired addition?

    Thanks, Martin.
      Martin Sanders - Design & Web Development
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You probably need to convert those dates into timestamps before trying to compare them.
        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
        • 26931
        • 2,314 Posts
        if you are useing Ditto you ould do something like this e.g.:
        &filter=`pub_date,@EVAL return strtotime('-4 day');,3|pub_date,@EVAL return strtotime('+1 week');,4`
        this will filter out all ressources that are older than 4 days, and all ressources with pub_date set more than 1 weeks in the future. you can also use a custom date TV
          • 19975
          • 429 Posts
          Hi, Thanks for the feedback.

          The element I’m looking to show between a set dates is a special offer price, the date only applies to the price deduction and not the doc publish from to parameters which would remain unaffected.

          I hope this helps.
            Martin Sanders - Design & Web Development
            • 19975
            • 429 Posts
            Any further suggestions would be very welcome
              Martin Sanders - Design & Web Development
              • 4041
              • 788 Posts
              You could use something like this snippet without using phx (with a little modding to fit your purpose)
              <?php
              $output ='';
              // the name of the date TV
              $date_tv_name ='my_date_tv';
              
              // name of the chunk
              $show_chunk_name ='FormLogin';
              
              // get the tv date info
              $tv_output = $modx->getTemplateVarOutput(array($date_tv_name));
              
              // make the TV date info into a timestamp
              $date_output = $modx->ToTimeStamp($tv_output[$date_tv_name]);
              
              // get current timestamp
              $current_time = time();
              
              // if date tv is greater than current time, show chunk
              if($date_output > $current_time){
                  $output .='{{'.$show_chunk_name.'}}';
              }
              
              return $output;
              ?>
                xforum
                http://frsbuilders.net (under construction) forum for evolution