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

    I’m using getResources to list upcoming events and I created 2 CSS classes to tell the user the status of a given event.

    I understand that I can achieve this by using the IF conditional snippet.

    Here’s my logic (algorithm):

    If the the event start date is < the current date, class="event_past"

    else

    class="event_pending"

    Here’s my first shot. Please tell me what seems wrong. Also, what’s the call to retrieve the current date?:

    <div class="
    [[!If?  
       &subject=`[[+tv.EventStartDate]]`  
       &operator=`LT`  
       &operand=`+currentdate`  
       &then=`event_past`  
       &else=`event_pending`  
    ]] 
    "
    </div>
    

      A MODx Fanatic
      • 5340
      • 1,624 Posts
      I think the problem is with the +currentdate. I don’t think that works as intended.

      How is your date formated?

      I would convert [[+tv.EventStartDate]] to a unix time: http://www.php.net/manual/en/function.time.php
      ... and use a snippet instead of +currentdate: create a snippet named CurrentDate and use time() to output the current date.

      Now your dates will look something like 1286679251 and they can easily be compared.

      Let me know if you need more help.
        • 30585
        • 833 Posts
        Thanks alot for pointing the obsvious,

        I think I kinda mixed it up a bit there. But this below should make more sense.

        Here’s what I actually intended:

        <div class="
        [[!If?  
           &subject=`[[+CurrentDate]]`  
           &operator=`LT`  
           &operand=`[[+tv.EventEndDate]]`  
           &then=`event_pending`  
           &else=`event_past`  
        ]] 
        "
        </div>


        Now, my EventEndDate TV is not formatted in any particular way. It’s input type is set to "Date" and the output to "Default". Do you think I still need to convert it to UNIX time?

          A MODx Fanatic
          • 5340
          • 1,624 Posts
          What’s the output of [[+CurrentDate]] and [[+tv.EventEndDate]] without the IF? I can’t test right now but if you have something like ’10 September 2010’ it won’t work because you are comparing strings and not dates.

          I think that the safest method is to use the Unix time; they will probably be compared as strings but I’m sure string ’1’ > ’2’. That means creating a snippet that converts your date to a unix time stamp and using that snippet as an output filter.

          Also, Snippets can be used as custom modifiers and filters. Simply put the Snippet name instead of the modifier. Example with a snippet named ’makeDownloadLink’:
          from http://rtfm.modx.com/display/revolution20/Input+and+Output+Filters



            • 30585
            • 833 Posts
            One last question and sorry to be such a pain.

            It’s already working, but you’re absolutely right, I should convert the time to UNIx timestamp, because the time math seems erroneous.

            I also did a final change to the if statement because the snippet tag I was using wasn’t valid.

            When I place the following snippet and TV calls on the document without the if statement,

            [[CurrentDate]] // [[*EventStartDate]]

            Only the EventStartDate TV is returned: // 2010-10-08 09:00:00

            The CurrentDate snippet doesn’t seem to be outputting anything.

            Here’s the snippet’s code:

            <?php
            time();


            And here’s the modified if statement with valid tags:

            <div class="
            [[!If?  
               &subject=`[[CurrentDate]]`  
               &operator=`LT`  
               &operand=`[[+tv.EventEndDate:strtotime]]`  
               &then=`event_pending`  
               &else=`event_past`  
            ]]
            "
            </div>

            If I can get this part working, I should be ok converting the date to a unix timestamp.

            Thanks again for all your help.
              A MODx Fanatic
              • 5340
              • 1,624 Posts
              return time();
              


              should work

              But what is the out put of [[+tv.EventEndDate:strtotime]]?
                • 30585
                • 833 Posts
                Quote from: cipa at Oct 10, 2010, 04:18 AM

                return time();
                


                should work

                But what is the out put of [[+tv.EventEndDate:strtotime]]?

                Beauty!

                it’s working!

                Here’s my final if statement for those interested:

                <div class="
                [[!If?  
                   &subject=`[[CurrentDate]]`  
                   &operator=`lt`  
                   &operand=`[[+tv.EventEndDate:strtotime]]` 
                   &then=`event_pending`  
                   &else=`event_past`  
                ]]
                "
                </div>


                I use +tv.EventEndDate:strtotime to output EventEndDate’s date in a unix format as Cipa suggested. This call is part of a getResources template
                  A MODx Fanatic