We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5689
    • 289 Posts
    I’ve been unable to find any forum posts about this, but if you know of one, I’d be thankful for the link. smiley

    I need to create a page on a Revolution site that displays a list of upcoming events with links to each event’s page. I did the same thing on an Evolution site a long time ago, but I used Ditto with some ugly eval work to filter out any events that are already over (there was a start date TV and an end date TV, so anything with an end date before the current date was filtered out). I’d like to use getResources, but from what I can see, there isn’t a good way to achieve the same outcome.

    This time I just have a single event date TV, and I want to filter out any even with a date on or after the current date. Any events that already happen should be filtered out.

    Any ideas on the best way to do this?

    Thanks!
      I'm learning more about MODx all the time and loving it.
      • 11139
      • 34 Posts
      I’ve done a little website to show a few MODx patterns, and that’s one of the patterns - a list of upcoming events with past ones filtered out.

      I’m trying to find time to make a good annotation document, but not finished it yet. However, each page in my site reveals the snippet calls and chunks, so you ought to be able to figure it out. It’s here : http://www.tgsketches.me.uk/cranford/

      You’ll need to know how to define the template variables:
      eventDate input type Date, output type Date, Date format %A, %d %B %Y (or whatever you’d prefer). Set ‘If no value, use current date’ to ‘No’ .
      todayDate input type Date, output type Date, Date format %A, %d %B %Y (or whatever you’d prefer). Set ‘If no value, use current date’ to ‘Yes’ .


      I’m afraid I got carried away and did the site in Victorian style, including bizarre fonts and Victorian colours.

      If you have any comments on whether it solved your problem and whether it made sense, I’d like to know. There may be things I still need to explain.

      Thomas
        • 5689
        • 289 Posts
        Thanks! There’s gotta be a better way to do it, but that’s working for me. It makes the most sense to filter out any past events ahead of time with the getResources snippet call, but unless somebody knows of a way to do that, this achieves the same thing, but it’s a little ugly because you’re including the chunk for every event and then simply outputting nothing if it’s a past event.

        I’m still open to better way, but thanks for the idea. This way is better than no way. smiley
          I'm learning more about MODx all the time and loving it.
          • 5689
          • 289 Posts
          By the way, rather than having a TV for today’s date, I just made a snippet called "today" that outputs a UNIX time code for today at midnight (in local time).

          <?php
          	return strtotime('today');
          ?>
          


          For anybody who stumbles upon this thread and wonders what I did, here’s the snippet call and the chunk.

          Snippet call to list events:
          [[!getResources? &parents=`[[*id]]` &sortbyTV=`eventDateTime` &sortdirTV=`ASC` &includeTVs=`1` &processTVs=`1` &tpl=`eventListing`]]
          


          Chunk (eventListing):
          [[!If?
             &subject=`[[+tv.eventDateTime]]`
             &operator=`>`  
             &operand=`[[!today]]`
             &then=`<div class="eventListing"><span>[[+tv.eventDateTime:date=`%m/%d (%a)`]]</span><a href="[[~[[+id]]]]">[[+longtitle]]</a></div>`
          ]]
          


          So I use getResources to list all events, using the eventListing chunk for each one. In the eventListing chunk, nothing is outputted if the event was in the past (it’s date is before today’s date); if the event has not yet happened or is happening today, it outputs the HTML for the listing.
            I&#39;m learning more about MODx all the time and loving it.
            • 11139
            • 34 Posts
            I think making a ’Today’ snippet is good for those who are happy with PHP, and I will keep a note of that solution, but I wanted to make a site where the workings would be obvious to newbies who didn’t want to explore PHP yet.

            Yes, I agree it’s ugly to send the events to the chunk and then not output anything. I don’t know how to do the filtering directly in getResources : anyone got a suggestion? -- In Evo, Ditto had a date filter but that seems to have been discarded in Revo’s getResources.

            Thomas
              • 22840
              • 1,572 Posts
              If im understanding this correctly you would have the following and only want it to display until the end of the day of the event:

              Event title
              event date
              Bit of intro text that explains the event
              Read More

              Why can’t you just use getResources, only show published event’s and use the publish date and un publish date in the page settings, that way the system will automatically un publish it on the given date and getResources will no longer pull it through ??
                • 5689
                • 289 Posts
                That would be too easy. tongue

                I actually did think of that, but I just don’t quite like the idea of it. To me, the dates of the event and the publish/unpublish dates of an article about the event should be entirely separate. I know it’s the same thing here, but there’s got to be a way to do it with my own date TV.
                  I&#39;m learning more about MODx all the time and loving it.
                  • 18373 ☆ A M B ☆
                  • 3,141 Posts
                  I’m currently working on a custom event manager component. For my specific case, it’s not using resources but saves the data in a seperate table and uses custom snippets to retrieve the data and style it using chunks. It has a "description" field, but at this point it’s not intended to provide a full-blown detail page, just a small description like Paulp posted, where "read more" is replaced with a "make a reservation" link in the sidebar.

                  It will integrate with FormIt through a custom hook to make the reservation, which will be viewable through the back-end component page and can be printed.


                  It’s not yet finished, but I am considering to release it when done.
                    Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                    Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                    • 5689
                    • 289 Posts
                    That sounds pretty useful. It’d probably be easy enough to have a way to link an event to a resource for full details, too.
                      I&#39;m learning more about MODx all the time and loving it.