tooth-paste Posted June 27, 2018 Posted June 27, 2018 I'm trying to build a calendar from a repeater field. One of the field is the date of an event. Is it possible to only display the items for today and later? Can I hide older items? Code: foreach($page->agendaitem as $item) { echo "<h4>{$item->activiteit}</h4><p> <b>{$item->datum} {$item->tijd}</b><br /> {$item->beschrijving} </p> <div class='stippellijnzwart'></div>"; }
wbmnfktr Posted June 27, 2018 Posted June 27, 2018 Honestly... go with pages for each event. It's much easier to handle and much easier to [everything]. Repeaters are nice but events/dates/calendar entries are more than just an item in a page. If you used pages instead of repeaters you could use: <?php $eventsToday = $pages->find("template=event, date=today"); ?> Just create a root element, for example: page with template events, for all your events and place all evens underneath it. 1
PWaddict Posted June 27, 2018 Posted June 27, 2018 @wbmnfktr Repeater items are actually pages too. @tooth-paste Here is how you can do it: <?php if(count($page->event_repeater)) { $today = strtotime("today"); $upcoming_dates = $page->event_repeater->find("event_date>=$today, sort=event_date"); if(count($upcoming_dates)) { foreach($upcoming_dates as $upcoming_date) { ?> <div>...</div> <?php } } } ?> 2
wbmnfktr Posted June 27, 2018 Posted June 27, 2018 6 minutes ago, PWaddict said: Repeater items are actually pages too. I totally agree with that but pages in pages under pages (repeaters) is something different. So plain pages are always more easily to control. 1
PWaddict Posted June 28, 2018 Posted June 28, 2018 2 hours ago, wbmnfktr said: I totally agree with that but pages in pages under pages (repeaters) is something different. So plain pages are always more easily to control. I think it depends on the content.
tooth-paste Posted June 28, 2018 Author Posted June 28, 2018 6 hours ago, PWaddict said: @wbmnfktr Repeater items are actually pages too. @tooth-paste Here is how you can do it: <?php if(count($page->event_repeater)) { $today = strtotime("today"); $upcoming_dates = $page->event_repeater->find("event_date>=$today, sort=event_date"); if(count($upcoming_dates)) { foreach($upcoming_dates as $upcoming_date) { ?> <div>...</div> <?php } } } ?> Thx! works perfect!
tooth-paste Posted June 28, 2018 Author Posted June 28, 2018 Can I place the code on another page (like homepage, recent three)? if(count($page->agendaitem)) { $today = strtotime("today"); $upcoming_dates = $page->agendaitem->find("agenda_datum>=$today, sort=agenda_datum"); if(count($upcoming_dates)) { foreach($upcoming_dates as $upcoming_date) { echo "<h4>{$upcoming_date->agenda_activiteit}</h4><p> <b>{$upcoming_date->agenda_datum} {$upcoming_date->agenda_tijd}</b><br /> {$upcoming_date->agenda_beschrijving} </p> <div class='stippellijnzwart'></div>"; } } }
PWaddict Posted June 28, 2018 Posted June 28, 2018 @tooth-paste Of course just add a limit on your selector like this: $upcoming_dates = $page->agendaitem->find("agenda_datum>=$today, sort=agenda_datum, limit=3");
tooth-paste Posted June 28, 2018 Author Posted June 28, 2018 @PWaddict: Thank you, but can I place the code on a different page(homepage)? I tried the following code but it does not work. I added 'get' $upcoming_dates = $pages->get("/agenda")->agendaitem->find("agenda_datum>=$today, sort=agenda_datum, limit=3");
PWaddict Posted June 28, 2018 Posted June 28, 2018 10 minutes ago, tooth-paste said: @PWaddict: Thank you, but can I place the code on a different page(homepage)? I tried the following code but it does not work. Sorry my mistake. The selector code if placed on another page must be $pages->find. Try this: $upcoming_dates = $pages->find("template=your_event_template, agenda_datum>=$today, sort=agenda_datum, limit=3");
tooth-paste Posted June 28, 2018 Author Posted June 28, 2018 This line doesn't work. Could it have to do with the repeater 'agendaitem'? $upcoming_dates = $pages->agendaitem->find("template=agenda, agenda_datum>=$today, sort=agenda_datum, limit=3");
PWaddict Posted June 28, 2018 Posted June 28, 2018 Try the below but on the template enter the name of the repeater template. If you go to "Setup > Templates > Filters > Show system templates? > Yes" you'll find that your repeater field has a template like this: repeater_your_event_repeater: $upcoming_dates = $pages->find("template=repeater_your_event_repeater, agenda_datum>=$today, sort=agenda_datum, limit=3");
tooth-paste Posted June 28, 2018 Author Posted June 28, 2018 Nope:( The template is called: repeater_agendaitem. In my original code the repeater is included but not in your example. Is this necessary? $page->agendaitem
PWaddict Posted June 28, 2018 Posted June 28, 2018 I've never output repeater content outside from their pages so maybe I'm not the right guy to help you. Until someone else can reply you should check the Repeater demonstration page on the part "Finding pages by repeater value (using selectors)".
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now