I had created a custom module for the news grid and form in Magento admin. I need to create custom pages with news collection on my custom news list page and a custom news detail page. How could I get the collection on frontend in magento 1.9?

I had created the custom admin grid please check the attached screenshot for the same. enter image description here

This is my custom news frontend page. enter image description here

Here is my custom layout file:


<?xml version="1.0"?>
<layout version="0.1.0">
    <reference name="content">
        <block type="news/news" name="news" template="custom/news/news.phtml" />

Here is my Block file:


<?php class Custom_News_Block_News extends Mage_Core_Block_Template { 
public function __construct()
    $news = Mage::getModel('news/news')->getNews();

protected function _prepareLayout()

    $toolbar = $this->getToolbarBlock();

    // called prepare sortable parameters
    $news = $this->getNews();

    // use sortable parameters
    if ($orders = $this->getAvailableOrders()) {
    if ($sort = $this->getSortBy()) {
    if ($dir = $this->getDefaultDirection()) {

    $this->setChild('toolbar', $toolbar);
    return $this;

protected function _getNewsCollection()
    if (is_null($this->_newsCollection)) {
        $newsCollection = Mage::getModel('news/news')->getNewsCollection();

        $this->_newsCollection = $newsCollection;

    return $this->_newsCollection;

public function getDefaultDirection(){
    return 'asc';
public function getAvailableOrders(){
    return array('created_time'=> 'Created Time','update_time'=>'Updated Time','id'=>'ID');
public function getSortBy(){
    return 'id';
public function getToolbarBlock()
    $block = $this->getLayout()->createBlock('news/toolbar', microtime());
    return $block;
public function getMode()
    return $this->getChild('toolbar')->getCurrentMode();

public function getToolbarHtml()
    return $this->getChildHtml('toolbar');
} }

Here is my template file to get news list:


<?php echo $this->getMessagesBlock()->getGroupedHtml() ?> 
<?php $newsCollection = $this->getNewsCollection(); ?>
<div class="custom-news">
    <h1><?php echo $this->__('My News Collection') ?></h1>
<?php echo $this->getToolbarHtml(); ?>
<?php if($collection->getSize()): ?>

<?php if($this->getMode() == 'list'){ ?>
<table class="custom-news-table" id="custom_news">
    <col width="1" />
    <col width="1" />
    <col />
    <col width="1" />
    <col width="1" />
    <col width="1" />
            <th><?php echo $this->__('ID #') ?></th>
            <th><?php echo $this->__('Title') ?></th>
            <th><span class="nobr"><?php echo $this->__('Created') ?></span></th>
        <?php $_odd = ''; ?>
        <?php foreach ($news as $_obj): ?>
            <td><?php echo $_obj->getId() ?></td>
            <td><span class="nobr"><?php echo $_obj->getTitle(); ?></span></td>
            <td><?php echo $this->formatDate($_obj->getCreatedTime()) ?></td>
        <?php endforeach; ?>
<script type="text/javascript">decorateTable('custom_news');</script>
<?php }else{ ?>
    <!-- List Mode HTML Here -->
<?php } ?>
<?php echo $this->getToolbarHtml(); ?>
<?php else: ?>
    <p><?php echo $this->__('The News collection is empty.'); ?></p>
<?php endif; ?>

Please provide the solution to get the custom collection on the frontend with list and detail pages.


Call below code instead


 <?php $newsCollection = $this->getNewsCollection(); ?>

Replace :

  <?php $newsCollection = $this->_getNewsCollection(); ?>
  • Hii @gaurang I tried your solution but it didn't work. My Template is not generated on frontend. Please check the attached updated screenshot of frontend. – MOHAMMED UBED SHAIKH Dec 2 at 12:02
  • call url news/index/index not custom_news – padhiyar gaurang Dec 2 at 12:40
  • The news/index/index takes me to the 404 page. The url should run with custom_news only, as I had mentioned the front router name in my module's config.xml file. – MOHAMMED UBED SHAIKH Dec 2 at 12:54
  • check your logs – padhiyar gaurang yesterday
  • Hello @gaurang, I had checked my logs and it shows this error: "Error in file: "/home/ubuntu/magento1943/app/code/local/Custom/News/sql/news_setup/mysql4-install-0.1.0.php" - SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'custom_news' already exists" – MOHAMMED UBED SHAIKH yesterday

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.