Skip to content

Instantly share code, notes, and snippets.

@hissy hissy/filter_by_date.php
Last active Dec 6, 2018

Embed
What would you like to do?
#concrete5 #v8 An example of the custom template of page list: filter by date time attribute
<?php
defined('C5_EXECUTE') or die("Access Denied.");
/** @var \Concrete\Core\Page\PageList $list */
// Start Date is earlier than tomorrow
$tomorrow = \Carbon\Carbon::tomorrow();
$list->filterByAttribute('start_date', $tomorrow->format('Y-m-d'), '<');
// End Date is later than today
$today = \Carbon\Carbon::today();
$list->filterByAttribute('end_date', $today->format('Y-m-d'), '>=');
$list->setItemsPerPage($controller->num);
if ($controller->num > 0) {
$pagination = $list->getPagination();
$pages = $pagination->getCurrentPageResults();
} else {
$pages = $list->getResults();
}
$c = Page::getCurrentPage();
/** @var \Concrete\Core\Utility\Service\Text $th */
$th = Core::make('helper/text');
/** @var \Concrete\Core\Localization\Service\Date $dh */
$dh = Core::make('helper/date');
if ($c->isEditMode() && $controller->isBlockEmpty()) {
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.