https://github.com/heimrichhannot/contao-newsnavigation-bundle
Add previous and next article template tags to a news article
https://github.com/heimrichhannot/contao-newsnavigation-bundle
Last synced: 2 months ago
JSON representation
Add previous and next article template tags to a news article
- Host: GitHub
- URL: https://github.com/heimrichhannot/contao-newsnavigation-bundle
- Owner: heimrichhannot
- License: lgpl-3.0
- Created: 2017-10-10T10:45:53.000Z (over 8 years ago)
- Default Branch: v3
- Last Pushed: 2024-11-28T11:33:27.000Z (over 1 year ago)
- Last Synced: 2025-10-24T05:47:42.001Z (6 months ago)
- Language: PHP
- Size: 87.9 KB
- Stars: 1
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Contao Newsnavigation Bundle
[](https://packagist.org/packages/heimrichhannot/contao-newsnavigation-bundle)
[](https://packagist.org/packages/heimrichhannot/contao-newsnavigation-bundle)
[](https://packagist.org/packages/heimrichhannot/contao-newsnavigation-bundle)

A [contao](https://contao.org/de/) extension to provide a simple navigation between news articles. It add template variables to go from one news article to the next or the previous article.
News article order is calculated by time property.

## Features
* add Template variables to NewsReaderModule to jump between news articles
* customize article navigation with custom filters
## Installation
Install via composer:
```
composer require heimrichhannot/contao-newsnavigation-bundle
```
## Usage
The bundle provides two new variables for news reader templates: `nextArticle` and `previousArticle`.
Twig example:
```twig
{% if previousArticle|default %}
{{ previousArticle.label }}
{% endif %}
{% if nextArticle|default %}
{{ nextArticle.label }}
{% endif %}
```
HTML5 example:
```php
previousArticle): ?>
= $this->previousArticle->label ?>
nextArticle): ?>
= $this->nextArticle->label ?>
```
## Customize article navigation
To customize which articles are shown as next and previous, you can use the [NewsNavigationFilterEvent](src/Event/NewsNavigationFilterEvent.php) event.
It gets passed a filter instance and the `ModuleModel` instance.
To modify the filter, use the methods of the filter object.
Example:
```php
use HeimrichHannot\NewsNavigationBundle\Event\NewsNavigationFilterEvent;
function __invoke(NewsNavigationFilterEvent $event): void
{
if ($event->model->someCustomTstamp) {
$event->filter->setColumns(array_merge($event->filter->getColumns(), ['someCustomTstamp>=?']));
$event->filter->setValues(array_merge($event->filter->getValues(), [$event->model->someCustomTstamp]));
}
if (!empty(StringUtil::deserialize($event->moduleModel->categories, true))) {
$filter->setColumns(array_merge($filter->getColumns(), ['tl_news.categories IN (?)']));
$filter->setValues(array_merge($filter->getValues(), StringUtil::deserialize($event->moduleModel->categories, true)));
}
}
```