heimrichhannot/contao-newsnavigation-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

heimrichhannot/contao-newsnavigation-bundle

最新稳定版本:3.0.1

Composer 安装命令:

composer require heimrichhannot/contao-newsnavigation-bundle

包简介

A bundle to provide a navigation between news articles

README 文档

README

A contao 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.

screenshot.png

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:

{% if previousArticle|default %}
    <a href="{{ previousArticle.url }}" class="previous">
        {{ previousArticle.label }}
    </a>
{% endif %}

{% if nextArticle|default %}
    <a href="{{ nextArticle.url }}" class="next">
        {{ nextArticle.label }}
    </a>
{% endif %}

HTML5 example:

<?php if ($this->previousArticle): ?>
    <a href="<?= $this->previousArticle->url ?>" title="<?= $this->previousArticle->title ?>"><?= $this->previousArticle->label ?></a>
<?php endif; ?>
<?php if ($this->nextArticle): ?>
    <a href="<?= $this->nextArticle->url ?>" title="<?= $this->nextArticle->title ?>"><?= $this->nextArticle->label ?></a>
<?php endif; ?>

Customize article navigation

To customize which articles are shown as next and previous, you can use the NewsNavigationFilterEvent event. It gets passed a filter instance and the ModuleModel instance. To modify the filter, use the methods of the filter object.

Example:

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)));
    }
}

统计信息

  • 总下载量: 1.68k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 5
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2017-10-10