MODX Community

GetResources - Show certain Pages at certain Times

I’d love to pick your brains. I have a website with this family tree layout below. On the Schedule Page, I’m showing the full list of programmes for the day using getResources. So I have a Wayfinder retrieving the Days in a list and when you click on a certain day, it shows the content from that day.

Here’s where it get tricky. On the Home Page, I’d like to show the Programmes for a certain day only. So today for example is Friday, it would show the Friday Schedule and when you go on the website tomorrow, it would show the Saturday schedule. Can I do that with getResources or should I create a Snippet?

  1. Home
  2. About
  3. News
  4. Schedule
    ** Monday
    ***** Programme 09:00
    ***** Programme 12:00
    ***** Programme 15:00
    ** Tuesday
    ***** Programme 09:00
    ***** Programme 12:00
    ***** Programme 15:00
    ** Wednesday
    ***** Programme 09:00
    ***** Programme 12:00
    ***** Programme 15:00
    ** Thursday
    ***** Programme 09:00
    ***** Programme 12:00
    ***** Programme 15:00
    ** Friday
    ***** Programme 09:00
    ***** Programme 12:00
    ***** Programme 15:00
    ** Saturday
    ***** Programme 09:00
    ***** Programme 12:00
    ***** Programme 15:00
    ** Sunday
    ***** Programme 09:00
    ***** Programme 12:00
    ***** Programme 15:00
  5. Contact Us

I have sorted it but not 100% sure if it’s right but it works. I created a snippet that ran an Array and inside each array, I put a getResources for that Day ID.

<?php
  $schedule = array(
    'Monday' => 'Monday Schedule',
    'Tueday' => 'Tueday Schedule',
    'Wednesday' => 'Wednesday Schedule',
    'Thursday' => 'Thursday Schedule getResources',
    'Friday' => '[[!getResources?
                    &parents=`33`
                    &depth=`1`
                    &limit=`0`
                    &tpl=`scheduleList`
                    &includeContent=`1`
                    &includeTVs=`1`
                    &processTVs=`1`
                    &showHidden=`1`
                    &sortby=`menuindex`
                    &sortdir=`ASC`
                  ]]',
    'Saturday' => 'Saturday Schedule',
    'Sunday' => 'Sunday Schedule',
  );

  $day_today = date('l');
  
  echo $schedule[$day_today];

That’ll work. Should change that echo at the end to a return to be more correct, though.

Probably don’t need to call those getResources call uncached, although you will need to call your own snippet uncached (or wrapped with getCache) to make it take effect automatically.

Another option could be to output the entire schedule for all days, but use only a dynamic CSS class (based on your snippet) to determine which ones are shown and which ones aren’t. Could even extend that to allow people choose what day to show, in case they want to look ahead at your schedule for tomorrow.

Thanks MarkH. I’ve done those changes. Can I ask…how do you call a Snippet uncached?

It’s working a treat. I’m thinking of adding to it. I’d like to show only the programmes that haven’t aired yet. So as it’s almost5pm now, anything before 5m will not be visible on the list. Is that possible with getResources or do i have to add to my Snippet?

Simply put a ! inside your tag like this [[!uncachedSnippet]], instead of calling it like this: [[cachedSnippet]]

1 Like

I’m using the tvFilter to show Programmes by Time. Below is my getResources. It’s returning my folder for Monday using the TV scheduleStartTime. I’m trying to get it to show the Programmes where the TV scheduleStartTime is greater than the current time. Not sure how to set the current time though. I created another Snippet returning the Time and added that Snippet below but no joy. Any thoughts?

[[!getResources?
  &parents=`25`
  &depth=`1`
  &limit=`0`
  &tpl=`scheduleListHomepage`
  &includeContent=`1`
  &includeTVs=`1`
  &processTVs=`1`
  &showHidden=`1`
  &sortby=`menuindex`
  &sortdir=`ASC`
  &tvFilters=`scheduleStartTime>>[[!currentTime:date=`%I:%M %p`]]`
]]'