We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38462
    • 39 Posts
    I am looking for a way to to display slightly different content inside a tplchunk if a newly added resource is only 30 days old. I've tried to work with the following info https://forums.modx.com/thread/82179/getresources-where-published-date-is-older-than however I am totally stumped. [ed. note: northernape last edited this post 13 years, 1 month ago.]
      • 37242 ☆ A M B ☆
      • 339 Posts
      I hava a calendar (with two different views) which is "upcoming" and "past events". "order" is by date ACS / DESC.

      You want it different, changing just the tpl. Maybe you dont need to. Because: you have the TV which is nessesary to filter / select the upcoming / current events. So you can use that TV inside the tpl chunk like:

      If the difference between today and date_of_document id >30d, then please write class="event old" instead of class="event current".

      So you need the today snippet (which returns the current date) and an output modifier from here.

      Cheers!
        • 38462
        • 39 Posts
        Quote from: gallenkamp at Jun 07, 2013, 05:53 AM

        So you need the today snippet (which returns the current date) and an output modifier from here.

        dateToday snippet
        <?php
        /* stringToTime snippet */
        return strtotime($input);


        Like so ?
        [[+publishedon:gt=`[[!dateToday? &input=`-30 days`]]`:then=`event old`:else=`event new`]]
          • 37242 ☆ A M B ☆
          • 339 Posts
          I would start that way, yes smiley

          Maybe the syntax isnt right yet, I can't tell. But this approach should work.
            • 32699 ☆ A M B ☆
            • 427 Posts
            Try:
            [[!getNow]]
            <?php
            // last month
            return mktime(0, 0, 0, date("m")-1, date("d"), date("Y"));
            


            <div class="[[+publishedon:lt=`[[!getNow]]`:then=`event old`:else=`event new`]]"></div>
            


            Off the top of my head but i have done this many times.
              Get your copy of MODX Revolution Building the Web Your Way http://www.sanitypress.com/books/modx-revolution-building-the-web-your-way.html

              Check out my MODX || xPDO resources here: http://www.shawnwilkerson.com
              • 38462
              • 39 Posts
              I've tried both solutions - just keeps defaulting to "event old". All looks like both solutions should work. Any ideas?

              I've tried a cached and uncached getResources call. [ed. note: northernape last edited this post 13 years, 3 months ago.]
                • 32699 ☆ A M B ☆
                • 427 Posts
                Ohh.. the reason why is the chuck is grabbed during the get resources bad.

                If you noticed I created a class change so that you could use the same layout but with a different class, which should give you what you want.

                I did something similar here: http://www.z-cellular.com/ The first box has an added class based on the name of the Program being referred to.

                  Get your copy of MODX Revolution Building the Web Your Way http://www.sanitypress.com/books/modx-revolution-building-the-web-your-way.html

                  Check out my MODX || xPDO resources here: http://www.shawnwilkerson.com
                  • 32699 ☆ A M B ☆
                  • 427 Posts
                  Ohh.. the reason why is the chuck is grabbed during the get resources load. It has no way of knowing what the publishedon (or any other attribute is) when the chunk is defined.

                  If you noticed I created a class change so that you could use the same layout but with a different class, which should give you what you want.

                  I did something similar here: http://www.z-cellular.com/ The first box has an added class based on the name of the Program being referred to.

                  I just placed it in the chunk where I needed it to change.

                    Get your copy of MODX Revolution Building the Web Your Way http://www.sanitypress.com/books/modx-revolution-building-the-web-your-way.html

                    Check out my MODX || xPDO resources here: http://www.shawnwilkerson.com
                    • 38415 ☆ A M B ☆
                    • 70 Posts
                    If your &sortBy field is "publishedon" too, you could use two different getResources calls with different chunks like this:

                    [[getResources? &parents=`1` &where=`{"publishedon:<=": [[!strtotime? &input=`-30 days`]] }` &tpl=`new_resources_tpl`]]

                    [[getResources? &parents=`1` &where=`{"publishedon:>=": [[!strtotime? &input=`-30 days`]] }` &tpl=`old_resources_tpl`]]
                      chsmedien - Digital Marketing Agency
                      MODX Professional & Ambassador

                      http://chsmedien.com | http://twitter.com/christianseel
                      • 38462
                      • 39 Posts
                      Chistian,
                      I like your thinking. However, the only possible problem I have with this route, my getResource call within on resource template is limited to '4'. Thanks, will give it a whirl.