Contao Newsnavigation Bundle
, (*1)
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., (*2)
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:, (*3)
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., (*4)
Example:, (*5)
<?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., (*6)
Developers
Template variables
This extension adds following template tags to the news template model, which you can use in your templates:, (*7)
name |
description |
nextArticle |
Next (newer) article id |
previousArticle |
Previous (older) article id |
nextArticleLabel |
Next article label ("Next article") |
previousArticleLabel |
Previous article label ("Previous article") |
If you want the news title instead the next/previous article label, see #1 how to do this., (*8)
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:, (*9)
Examples:, (*10)
// 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:, (*11)
$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();