PHP code example of heimrichhannot / contao-news-pagination-bundle

1. Go to this page and download the library: Download heimrichhannot/contao-news-pagination-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

heimrichhannot / contao-news-pagination-bundle example snippets


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