Problems, need help? Have a tip or advice? Post it here.
8 posts Page 1 of 1
I understand that I need to compare two dates: today and the event date. I have sort of done that in the code below, but it still shows all the events.

Code: Select all
<cms:set event_date="<cms:get_custom_field 'event_date' masterpage='bands.php'/>" />
<cms:if event_date ge "<cms:date format='Y-m-d H:i:s' />" >
   <cms:pages masterpage='bands.php' limit='6' orderby='weight' order='asc'>
         <h3><cms:show k_page_title /> - <cms:date event_date format='jS M Y'/></h3>
         <p><cms:show event_desc /></p>
   </cms:pages>
<cms:else/>
      <p>Check back later for new events!</p>
</cms:if>


The contents of bands.php:
Code: Select all
<cms:template title='Bands' clonable='1' order='5' >

    <cms:editable type='datetime' name='event_date' label='Event date'/>
    <cms:editable type='nicedit' name='event_desc' label='Event description' />

    <cms:config_list_view orderby='weight' order='asc'>
      <cms:field 'k_selector_checkbox' />
      <cms:field 'k_page_title' sortable='0' />
      <cms:field 'event_date' header='Event date' sortable='1'>
         <cms:date event_date format='jS M y' />
      </cms:field>
      <cms:field 'k_actions' />
   </cms:config_list_view>

</cms:template>


What will be the best way to display only upcoming events where the date is either equal or higher than today date?
We need to use the 'custom_field' param of <cms:pages> - please see viewtopic.php?f=4&t=8115#p14132 for an example.

Hope this helps.
Thanks for pointing me to the correct direction KK!

I have got it to work with the following code:
Code: Select all
<cms:set today="<cms:date format='Y-m-d H:i:s' />" />
<cms:if today le "<cms:get_custom_field 'event_date' masterpage='bands.php'/>" >
   <cms:pages masterpage='bands.php' custom_field="event_date >= <cms:show today />" limit='6' orderby='weight' order='asc'>
         <h3><cms:show k_page_title /> - <cms:date event_date format='jS M Y'/></h3>
         <p><cms:show event_desc /></p>
   </cms:pages>
<cms:else/>
      <p>Check back later for new events!</p>
</cms:if>
@aleks, your bands.php is a clonable template and the following operation is not taking this into account, rendering flawed logic -
Code: Select all
<cms:get_custom_field 'event_date' masterpage='bands.php'/>


Full code listing must be rewritten using 'cms:no_results' tag.
Thanks for your reply Trendoman.

cms:no_results tag is not included in tag reference section of documentation.

Can you share your insight on how the correct logic should look in my case?
aleks wrote: Thanks for your reply Trendoman.

cms:no_results tag is not included in tag reference section of documentation.

Can you share your insight on how the correct logic should look in my case?


You'll find that tag in forum viewtopic.php?f=5&t=7377
I've got rid of if/else statement and ended up with the following:
Code: Select all
<cms:set today="<cms:date format='Y-m-d H:i:s' />" />
<cms:pages masterpage='bands.php' custom_field="event_date >= <cms:show today />" limit='6' orderby='weight' order='asc'>
   <h3><cms:show k_page_title /> - <cms:date event_date format='jS M Y'/></h3>
   <p><cms:show event_desc /></p>
   <cms:no_results>
      <p>Check back later for new events!</p>
   </cms:no_results>
</cms:pages>

Is that getting any closer to what you were referring to?
Yes, right. It's what I meant. Good job :)
8 posts Page 1 of 1