i got this error while load new product collection in my custom cms page
protected function _prepareLayout()
{
parent::_prepareLayout();
$this->pageConfig->getTitle()->set(__('Best Seller'));
if ($this->getCollection()) {
$pager = $this->getLayout()->createBlock('Magento\Theme\Block\Html\Pager','newproduct.history.pager')->setAvailableLimit(array(5=>5,10=>10,15=>15,20=>20));
$pager->setLimit(5)->setShowPerPage(true);
$pager->setCollection($this->getCollection());
$this->setChild('pager', $pager);
$this->getCollection()->load();
}
return $this;
}
public function getPagerHtml(){
return $this->getChildHtml('pager');
}
public function getCollection(){
$page=($this->getRequest()->getParam('p'))? $this->getRequest()->getParam('p') : 1;
$pageSize=($this->getRequest()->getParam('limit'))? $this->getRequest()->getParam('limit') : 100;
$collection = $this->_productsFactory->create()
->addAttributeToSelect('*')
->setOrder('entity_id','desc')
->setPageSize(20)
->setPageSize($pageSize)->setCurPage($page);
return $collection;
}
Error
Error filtering template: Element with ID 'newproduct.history.pager' already exists.
How to fix this issue