heimrichhannot / contao-newsnavigation-bundle
A bundle to provide a navigation between news articles
Installs: 1 557
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 6
Forks: 0
Open Issues: 0
Type:contao-bundle
Requires
- php: ^7.0 | ^8.0
- contao/core-bundle: ^4.4.0
Requires (Dev)
- contao/manager-plugin: ^2.0
- friendsofphp/php-cs-fixer: ^2.2
- phpunit/phpunit: ^6.0
- satooshi/php-coveralls: ^1.0
README
A contao bundle 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
- option to respect news archives set in NewsReaderModule
- add custom filters via service
Requirements
- Contao 4.4 (could also work with earlier contao 4 versions)
Installation
Install via composer:
composer require heimrichhannot/contao-newsnavigation-bundle
Usage
Template variables
To use this extension, you need to output the template variables in your custom news template.
Example:
<?php if ($this->previousArticle): ?>
<a href="{{news_url::<?= $this->previousArticle ?>}}" class="previous">
<?= $this->previousArticleLabel ?>
</a>
<?php endif; ?>
Newsarchives
To let the navigation respect only news archives set in NewsReaderModule, you find an option in the module backend.
Developers
Template variables
This extension adds following template tags to the news template model, which you can use in your templates:
If you want the news title instead the next/previous article label, see #1 how to do this.
Custom filters
The module allow a simple mechanic to add custom filters for the news navigation. You need to set additional filters to the huh.newsnavigation.newsfilter
before the parseArticles
Hook (from this module) of the NewsReaderModel is called. You can use following methods:
Examples:
// add additional database conditions
System::getContainer()->get('huh.newsnavigation.newsfilter')->addFilter('tl_news.newsCategory=?', 'contao4bundles');
// add additions options
System::getContainer()->get('huh.newsnavigation.newsfilter')->setOption('limit', '5');
Custom filter use
You can use the filter in custom way:
$filter = System::getContainer()->get('huh.newsnavigation.newsfilter');
// Creates a new filter object which contains all filters
$newFilter = $filter->createCopy();
// Create a new empty newsfilter instance
$newFilter = new HeimrichHannot\NewsNavigationBundle\NewsFilter\NewsFilter();
// Return the filter rules
$filter->getColumns()
$filter->getValues()
$filter->getOptions()
// Override filter rules
$filter->setColumns();
$filter->setValues();
$filter->setOptions();
// Change or return model
$filter->setModel();
$filter->getModel();