We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3722
    • 171 Posts
    I have a registration button setup in a chunk. (regButton)
    I have it displayed on the page, but want to hide it once the event date passes.
    Does anyone have an idea on how to do this?

    Here is what I have tried with no luck.

    [[*eventDate:gt=`[[!dateToday]]`:then=`[[$regButton]]`:else=``]]


    Using the If add on. Not sure if operands support TV's.
    [[!If?
       &subject=`[[+dateToday]]`
       &operator=`<`
       &operand=`[[*eventDate]]`
       &then=`[[$regButton]]`
       &else=``
    ]]


    Thanks
    BG66

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

    • Do it in a snippet. There you can interrogate the current date, then return the chunk if the $eventDate has not passed, otherwise return nothing.

      <?php
      if(time() < $eventDate){
          return $modx->getChunk('regButton');
      }
      return "";
        • 3749
        • 24,544 Posts
        Note that this will only work if $eventDate is a unix timestamp (if it's just a number when you display it, it should be fine). If it's a human-readable date/time (which MODX returns by default for all date fields), you'd have to convert it:

        if(time() < strtotime($eventDate)){
          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
          • 3722
          • 171 Posts
          Quote from: chrischerrett at Oct 22, 2014, 01:39 PM
          Do it in a snippet. There you can interrogate the current date, then return the chunk if the $eventDate has not passed, otherwise return nothing.

          <!--?php
          if(time() < $eventDate){
              return $modx--->getChunk('regButton');
          }
          return "";

          Thanks, this is almost working.
          I can only get the button to post when I reverse the less than "<" symbol to greater than ">".
          I also played around with different php and unix date code formats with no luck.

          My snippet call on the page is
          [[registrationButton]]


          My eventDate output options are
          %A, %B %d, %Y


          Thanks
          BG66
          • discuss.answer
            • 3749
            • 24,544 Posts
            Did you try my suggestion above for line 3?

            Are you sure $eventDate is set to some value in the snippet? Typically, you'd have to do something like this:

            [[registrationButton? &eventDate=`[[*eventDate]] ]]



            Then in the snippet:

            $eventDate = $modx->getOption('eventDate', $scriptProperties);
              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
              • 40045
              • 534 Posts
              what about caching issues, seems you're calling the snippet cached? How would it then re-evaluate the current date?
                • 3722
                • 171 Posts
                Thanks for everyone's help! It's working now!
                Here are the details.

                Template Variable:
                eventDate
                Output options
                %A, %B %e, %Y


                Chunk:
                regButton
                <a href="[[~27]]"><div class="button round">Register today!</div></a>


                Snippet:
                registrationButton
                <?php
                $eventDate = $modx->getOption('eventDate', $scriptProperties);
                if(time() < strtotime($eventDate)){
                    return $modx->getChunk('regButton');
                }
                return "";


                Snippet call on page:
                [[!registrationButton? &eventDate=`[[*eventDate]]` ]]


                Thanks
                BG66
                  • 3749
                  • 24,544 Posts
                  I'm glad you got it sorted. Thanks for reporting back. smiley
                    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
                    • 3722
                    • 171 Posts
                    Quote from: BobRay at Oct 23, 2014, 07:48 PM
                    I'm glad you got it sorted. Thanks for reporting back. smiley

                    Me too!
                    Thanks for the great support on a great product.
                    Thanks to BobRay, exside, and chrischerrett!!!