heimrichhannot / contao-news-pagination-bundle
为contao中的新闻或其他内容提供自动或手动内容分页。
2.6.1
2024-04-23 10:09 UTC
Requires
- php: ^8.1
- contao/core-bundle: ^4.13
- heimrichhannot/contao-head-bundle: ^1.12
- heimrichhannot/contao-utils-bundle: ^2.230
- symfony/http-foundation: ^5.4 || ^6.0
- wa72/htmlpagedom: ^1.3 || ^2.0
This package is auto-updated.
Last update: 2024-09-23 11:17:23 UTC
README
此包为contao核心新闻阅读器模块以及heimrichhannot/contao-reader-bundle提供自动内容分页。
特性
- 为新闻部分之间的导航添加分页
- 自动拆分
- 通过可调整的字符数量按HTML标签拆分新闻文章
- 手动拆分
- 通过将内容元素包裹在特殊的开始和结束内容元素中来拆分新闻内容
- 可选支持hofff/contao-content-navigation
使用方法
设置
-
使用composer或contao管理器安装
composer require heimrichhannot/contao-news-pagination-bundle
-
更新数据库
-
您将在新闻阅读器前端模块或阅读器配置中找到新的配置选项
-
将
<?= $this->newsPagination ?>
添加到您的详细信息模板中(例如“news_full”)以输出分页导航
自动分页的已知限制
- 目前仅支持嵌套在另一个内容元素(如手风琴)之外的ce_text进行拆分,其他元素虽然根据当前页码正确删除(完全删除),但不支持拆分
开发者
PaginationUtil
开发者可以通过使用PaginationUtil
脚本来执行自动分页。
示例
use HeimrichHannot\NewsPaginationBundle\Util\PaginationUtil; use Wa72\HtmlPageDom\HtmlPageCrawler; class ParseArticlesListener { /** @var PaginationUtil */ protected $paginationUtil; public function __invoke(FrontendTemplate $template, array $newsEntry, Module $module) { $result = $this->paginationUtil->paginateHtmlText($template->text, 500, 1, [ 'selector' => '.ce_text_custom div.text', 'removePageElementsCallback' => function (array $result, int $currentPage, int $page) { // Always show page 1 if (1 === $page) { return false; } // Insert custom html after page 3 if (3 === $page) { $someCustomInsertion = new HtmlPageCrawler('<div class="alert">Custom Notice!</div>'); $someCustomInsertion->insertAfter(end($result[$page])['element']); } // Remove all element not on the current page (default) return $page != $currentPage; } ]); } }