Problems, need help? Have a tip or advice? Post it here.
2 posts Page 1 of 1
Hi, great script by the way, loving it!

I do have a question though, is there a way to list all the events for the current year on the list view outside of the actual calendar? I want just a straight bulleted list of events as a sort of appointment view for the current year (All of the current year even past events in current year). Is this possible?

Also, I would like to show a list of the 4 upcoming events on the homepage, not sure if it's possible to get the list of events outside of the events page?

Thanks!
BlueCaret
Hello and welcome, Bluecaret :)

We can simply use cms:pages to list the events.

The cms:pages tag supports 'start_on' and 'stop_before' parameters that can be used to constrain the listed pages within a specified timeframe (IMP: these parameters expect dates to be in yyyy-mm-dd format).

So if we provide the date of the first day of first month this year as the 'start_on' and the date of the first day of first month next year as the 'stop_before' parameter, our job is done.

We can use a little PHP to calculate these days for us like this -
Code: Select all
<cms:php>
    global $CTX;

    // calculate timestamps for the dates
    $timestamp_1 = strtotime("1/1 this year"); // first day of first month this year
    $timestamp_2 = strtotime("1/1 next year"); // first day of first month next year
   
    // set the timestamps as Couch variables (my_start_date and my_stop_date)
    $CTX->set( 'my_start_date', date('Y-m-d', $timestamp_1), 'global' );
    $CTX->set( 'my_stop_date', date('Y-m-d', $timestamp_2), 'global' );
</cms:php>

The code above will set two Couch variables named 'my_start_date' and 'my_stop_date' that have the dates in the format accepted by cms:pages.
We can now simply use these variables as the mentioned parameters e.g.
Code: Select all
<cms:pages 
    masterpage='events.php'
    limit='4'
    show_future_entries='1'
    start_on=my_start_date
    stop_before=my_stop_date
>
    ...
</cms:pages>

Make sure to specify the name of your events template as the 'masterpage'.

Please notice that we are also setting the 'show_future_entries' to '1' because. by default, cms:pages ignores pages with future dates.

Hope this helps.
2 posts Page 1 of 1
cron