Skip to content

Instantly share code, notes, and snippets.

@fritzmg
Last active January 2, 2018 10:27
Show Gist options
  • Save fritzmg/aa4632be2231d77e7d6ec0e5e0a854ae to your computer and use it in GitHub Desktop.
Save fritzmg/aa4632be2231d77e7d6ec0e5e0a854ae to your computer and use it in GitHub Desktop.
Previous and next events in the event_full template of Contao.

Contao Event Pagination

This event_full template creates a previous and next pagination for events. It uses the same HTML structure as the default pagination template. Of course you can change that to your needs. Simply download the event_full.html5 template and put it in your /templates directory.

Known limitations:

  • It ignores the start and end field.
  • It is limited to events from the same calendar. Otherwise the target URL might be wrong.
  • It will not work if the auto_item parameter is disabled.
<?php
$this->getEventUrl = function($objEvent)
{
global $objPage;
return \Controller::generateFrontendUrl($objPage->row(), '/' . $objEvent->alias, null, true );
};
$objNextEvent = \CalendarEventsModel::findOneBy(
array("startDate > ?", "published = '1'", "pid = ?"),
array($this->startDate, $this->pid),
array('order' => 'startDate ASC'));
$objPreviousEvent = \CalendarEventsModel::findOneBy(
array("startDate < ?", "published = '1'", "pid = ?"),
array($this->startDate, $this->pid),
array('order' => 'startDate DESC'));
?>
<div class="event layout_full block<?= $this->class ?>">
<h1><?= $this->title ?></h1>
<p class="info"><time datetime="<?= $this->datetime ?>"><?= $this->date ?><?php if ($this->time): ?>, <?= $this->time ?><?php endif; ?></time></p>
<?php if ($this->recurring): ?>
<p class="recurring"><?= $this->recurring ?><?php if ($this->until) echo ' ' . $this->until; ?>.</p>
<?php endif; ?>
<?php if ($this->hasDetails): ?>
<?= $this->details ?>
<?php else: ?>
<div class="ce_text block">
<?= $this->teaser ?>
</div>
<?php endif; ?>
<?php if ($this->location): ?>
<p class="location"><?= $this->locationLabel ?>: <?= $this->location ?></p>
<?php endif; ?>
<?php if ($this->enclosure): ?>
<div class="enclosure">
<?php foreach ($this->enclosure as $enclosure): ?>
<p><?= Image::getHtml($enclosure['icon'], '', 'class="mime_icon"') ?> <a href="<?= $enclosure['href'] ?>" title="<?= $enclosure['title'] ?>"><?= $enclosure['link'] ?> <span class="size">(<?= $enclosure['filesize'] ?>)</span></a></p>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if ($objPreviousEvent || $objNextEvent): ?>
<!-- indexer::stop -->
<div class="pagination block">
<ul>
<?php if ($objPreviousEvent): ?>
<li class="previous">
<a href="<?= $this->getEventUrl($objPreviousEvent) ?>" title="<?= $objPreviousEvent->title ?>" class="previous">
&laquo;&nbsp;<?= $objPreviousEvent->title ?>
</a>
</li>
<?php endif; ?>
<?php if ($objNextEvent): ?>
<li class="next">
<a href="<?= $this->getEventUrl($objNextEvent) ?>" title="<?= $objNextEvent->title ?>" class="next">
<?= $objNextEvent->title ?>&nbsp;&raquo;
</a>
</li>
<?php endif; ?>
</ul>
</div>
<!-- indexer::continue -->
<?php endif; ?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment