Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save evgv/663383f0679592336771a518cef71ad0 to your computer and use it in GitHub Desktop.
Save evgv/663383f0679592336771a518cef71ad0 to your computer and use it in GitHub Desktop.
Magento. Add pagination to custom collection.

Add pagination to custom collection

Modify _prepareLayout() method of class what render your template

    protected function _prepareLayout()
    {
        parent::_prepareLayout();

        $pager = $this->getLayout()->createBlock('page/html_pager', {pager name});
        $pager->setAvailableLimit({collection limits});
        $pager->setCollection({collection});

        $this->setChild('pager', $pager);

        return $this;
    }
where
  • {pager name} - any unique name
  • {collection limits} - array with limit params like a 'array(10=>10)'
  • {collection} - your collection

Add pager in template

    <?php echo $this->getChildHtml('pager'); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment