1protected function _prepareLayout()
2{
3 parent::_prepareLayout();
4 $this->pageConfig->getTitle()->set(__('News'));
5
6
7 if ($this->getNews()) {
8 $pager = $this->getLayout()->createBlock(
9 'Magento\Theme\Block\Html\Pager',
10 'test.news.pager'
11 )->setAvailableLimit(array(5=>5,10=>10,15=>15))->setShowPerPage(true)->setCollection(
12 $this->getNews()
13 );
14 $this->setChild('pager', $pager);
15 $this->getNews()->load();
16 }
17 return $this;
18}
19
1public function getNews()
2 {
3 //get values of current page
4 $page=($this->getRequest()->getParam('p'))? $this->getRequest()->getParam('p') : 1;
5 //get values of current limit
6 $pageSize=($this->getRequest()->getParam('limit'))? $this->getRequest()->getParam('limit') : 1;
7
8
9 $newsCollection = $this->newscollectionFactory->create();
10 $newsCollection->addFieldToFilter('is_active',1);
11 $newsCollection->setOrder('title','ASC');
12 $newsCollection->setPageSize($pageSize);
13 $newsCollection->setCurPage($page);
14 return $newsCollection;
15 }
16
17
1 <?php if ($block->getPagerHtml()): ?>
2 <div class="order-products-toolbar toolbar bottom"><?php echo $block->getPagerHtml(); ?></div>
3 <?php endif ?>
4
1public function getPagerHtml()
2{
3 return $this->getChildHtml('pager');
4}
5