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.

    I have this snippet code by BobRay

    <?php
    /* 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()
                ? 'YES'
                : 'NO'
            ;
        }
    }
    return $output;
    


    Call:
    [[!DateCheck? &date=`[[*date]]` ]]


    The code is to compare the date from [[*date]] TV with the current date, then it will display YES OR NO as result.

    I need to feed the results with different things, in that case I'll need call the snippet like this:
    [[!DateCheck? &date=`[[*date]]` &isLower=`YEP` &isGreater=`NOP` ]]
    
    how can I do that?
    hope is clear, Thank you very much!

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

    [ed. note: Ysanmiguel last edited this post 7 years, 3 months ago.]
      --
      ysanmiguel.com
      • 36818
      • 119 Posts
      If I understand you correctly you want to pass some properties into to snippet.
      https://docs.modx.com/revolution/2.x/developing-in-modx/basic-development/snippets/how-to-write-a-good-snippet Here and https://docs.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/properties-and-property-sets here is a good starting point.

      Properties are passed into a snippet in different way. The easiest:
      [[snippet? &prop1]] 
      becomes
      $prop1
      in the snippet
        • 30585
        • 833 Posts
        Can you please explain what you're trying to achieve with those new properties?
          A MODx Fanatic
          • 33238
          • 388 Posts
          I'm not good with php, so technically I', guessing.
          and this is not working, can you please help me?
          Thank you!

          <?php
          /* DateCheck snippet */
          $date = $modx->getOption('date', $scriptProperties, '');
          $gt = $modx->getOption('gt', $scriptProperties, 'Greater');
          $lt = $modx->getOption('lt', $scriptProperties, 'Lower');
          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()
                      ? '$gt'
                      : '$lt'
                  ;
              }
          }
          return $output;



            --
            ysanmiguel.com
            • 33238
            • 388 Posts
            Quote from: treigh at Jan 18, 2017, 02:11 AM
            Can you please explain what you're trying to achieve with those new properties?

            I just want call the same snippet in different areas of the page (two or three) displaying different information but everything base on the same result.

            If the current date is lower than the date in the TV:

            &gt = greaterThan
            &lt = lowerThan

            1.
            display: Still available
            to do this I'll need something like:
            [[!DateCheck? &date=`[[*date]]` &gt=`Not available` &lt=`Still available` ]]


            2.
            In another area of the page and usign the same snippet result I'll need show a placeholder, for example:
            [[!DateCheck? &date=`[[*date]]` &gt=`[[+listFutureProducts]]` &lt=`[[+listProducts]]` ]]


            that is the basic idea.
            Thank you!
              --
              ysanmiguel.com
              • 36818
              • 119 Posts
               $output = $dateStamp >= time()  ? '$gt'   : '$lt';


              has to be

               $output = $dateStamp >= time()  ? $gt   : $lt;


              no quotes around $gt and $lt.
              • discuss.answer
                • 33238
                • 388 Posts
                Quote from: achterbahn at Jan 18, 2017, 09:58 AM
                 $output = $dateStamp >= time()  ? '$gt'   : '$lt';

                has to be
                 $output = $dateStamp >= time()  ? $gt   : $lt;

                no quotes around $gt and $lt.

                Mate it's working. Thank you very much for your help.

                - If someone need it:

                <?php
                /* DateCheck snippet */
                $date = $modx->getOption('date', $scriptProperties, '');
                $gt = $modx->getOption('gt', $scriptProperties, 'Greater');
                $lt = $modx->getOption('lt', $scriptProperties, 'Lower');
                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()
                            ? $gt
                            : $lt
                        ;
                    }
                }
                return $output;


                Call:
                [[!DateCheck? &date=`[[*date]]` &gt=`Greater Than Today` &lt=`Lower Than Today` ]]
                  --
                  ysanmiguel.com