We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36686
    • 165 Posts
    It took me some time to work out, but I managed to hide any past events by using getResources, a TV (myDate) with Date as Input and Output types, a today snippet and Output filters in MODx Revolution, like this:

    getResources call:

    [[!getResources? &sortbyTV=`myDate` &sortdirTV=`ASC` &includeTVs=`1` &processTVs=`0` &tpl=`myTpl`]]
    


    Chunk myTpl:

    [[+tv.myDate:greaterthanorequalto=`[[?today]]`:then=`[[+pagetitle]] and whatever other content you would like to show`:else=` `]]
    


    Snippet today:

    <?php
    $scriptProperties['format'] = $modx->getOption('format', $scriptProperties, "Y-m-d");
    return date($scriptProperties['format']);


    Works for me!
      • 38360
      • 20 Posts
      Sketchi your solution works for me but it has some limitations

      I have about 100 courses. I want to create a simple feature where you can see "next upcoming 3 courses".

      I make the same calls like you do. The resources are sorted by tvdate ASC so the most recent first.
      But my problem is that I set a &limit=`3` which stops processing the resources after the first 3. so if the first 3 courses already lie in the past. My snippet obviously returns nothing. If I set the limit to 100 I get to many courses...

      So I am badly looking for another solution.

      Another idea is to call a snippet whenever that site is called which goes through all 100 resources and checks if the TV date lies in the past. If so unpublish that resource. Like that your solution would work again, because in the top 3 of my list are only published resources.

      Any help would be much appreciated

      Thanks
        • 38360
        • 20 Posts
        any hints? would be much appreciated, because I am stuck here. Thanks so much
          • 38136
          • 42 Posts
          I solved this problem as following:

          I set up a snippet (toDay) which calls the actually date in a matter that sql understand it:

          <? return date("Y-m-d H:i:s"); ?>
          


          getResource i use as the following:

          [[!getResources?
            &parents=`[[*id]]`
            &hideContainers=`1`
            &showHidden=`1`
            &includeTVs=`1`
            &tvFilters=`eventdate>=[[!toDay]]`
            &sortbyTV=`eventdate`
            &sortdirTV=`ASC`
            &tpl=`commingTpl`
            &limit=`2`
          ]]
          


          tvFilters seems to do the magic.

          greetings
          • I had to use <? return date("Y-m-d"); ?>. Somehow the blank between data and time screwed it up. Since I did not need the time but only the date, that was fine for now.

            But:
            ...
            &tvFilters=`eventdate>=[[toDay]]`
            ...
            

            I also had to use the snippet uncached! Don't ask me why, but only then it worked.

            To get the uncached date, I put a "<!-- [[!toDay]] -->" into my HTML source code but that does not overwrite the cache. So my solution works today but will fail tomorrow. :-(

            Anyone any idea what might cause this strange behaviour? Or how to work around?
              MINDEFFECTS – DESIGN for PRINT, WEB and MEDIA
              http://twitter.com/mindeffects · http://www.facebook.com/mindeffects · http://www.youtube.com/mindeffects/ · skype://mindeffects_oliver
            • discuss.answer
              • 38136
              • 42 Posts
              did u set getResources to uncached?

              a better solution, when u do not need a time would be
              <? return date("Y-m-d 00:00:00"); ?>


              that would switch at midnight.
              • discuss.answer
                Quote from: mopox at Jan 17, 2013, 03:36 PM
                did u set getResources to uncached?
                And here we have the winner: NO, I did not. I just used the uncached TV, which did not work. BUT: Calling getResources uncached made the pig fly! YES! BAMM! THX SOOO MUCH!!! Also to Mark Hamstra who tweeted something similar.

                Here's the full code for my movie distributor website:

                The "dateToday" snippet:
                return date("Y-m-d");
                


                gR call for the NEW movies:
                [[!getResources?
                &parents=`2`
                &tvFilters=`cinemaReleaseDate<=[[!dateToday]]%,cinemaRepertoire!=1`
                &sortbyTV=`cinemaReleaseDate` &sortdirTV=`DESC`
                &includeTVs=`1`
                &tpl=`movieListCinema`
                &tpl_n4=`movieListCinemaBR`
                ]]
                

                The "%" in tvFilter is important because I only compare the date and NOT the time. Since the date TV autosets the current time when only a date is picked (bad widget!) the comparison needs to be reduced so that the time is not evaluated.

                gR call for the UPCOMING movies:
                [[!getResources?
                ...
                &tvFilters=`cinemaReleaseDate>>[[!dateToday]]%,cinemaRepertoire!=1`
                &sortbyTV=`cinemaReleaseDate` &sortdirTV=`ASC`
                ...
                ]]
                


                gR call for the REPERTOIRE movies:
                [[!getResources?
                ...
                &tvFilters=`cinemaReleaseDate<=[[!dateToday]]%,cinemaRepertoire==1`
                &sortbyTV=`cinemaReleaseDate` &sortdirTV=`DESC`
                ...
                ]]
                

                I hope, someone finds this usefull.

                cheers
                Oliver [ed. note: mindeffects last edited this post 11 years, 3 months ago.]
                  MINDEFFECTS – DESIGN for PRINT, WEB and MEDIA
                  http://twitter.com/mindeffects · http://www.facebook.com/mindeffects · http://www.youtube.com/mindeffects/ · skype://mindeffects_oliver
                  • 3722
                  • 171 Posts
                  mindeffects!

                  VERY useful!
                  I was struggling with this. I had my articles unpublished for past events. It worked fine when I was logged in. When I logged out, they did not appear and the links defaulted to my home page.
                  I applied this filter for both past and future events in different areas.
                  THANK YOU!!!
                    • 50960
                    • 17 Posts
                    BOOM POW. perfect solution Mindeffects.

                    Worked GREAT for a upcoming and past events through getResources or pdoResources.

                    Thanks!
                      Tink!