Magento custom module - can not call block method from template

advertisements

I'm working on a custom module to display CMS content. I have a custom front controller which is working as expected. I'm able to call various front actions from the controller. I am using an existing template, which is also displaying as it should. I'm also loading a layout update xml file, from which I was able to remove the product menu, which I don't need, and add a reference block for my custom block's template file.

I know the correct template override file is loading, as I'm testing with the following:

<?php echo __FILE__ . " loaded <br>"; ?>

Which is echoing the correct filename.

However, when I call my custom block method from that same template file, I get nothing.

My module namespace/module is Cmpreshn/Projects. Following is what I have so far:

Config file in app/code/local/Cmpreshn/Projects/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Cmpreshn_Projects>
            <version>0.1.0</version>
        </Cmpreshn_Projects>
    </modules>
    <frontend>
        <routers>
            <projects>
                <use>standard</use>
                <args>
                    <module>Cmpreshn_Projects</module>
                    <frontName>education</frontName>
                </args>
            </projects>
        </routers>
    <layout>
        <updates>
            <projects>
                <file>projects.xml</file>
            </projects>
        </updates>
    </layout>
    </frontend>
    <global>
        <blocks>
            <projects>
                <class>Projects_Block_List</class>
            </projects>
        </blocks>
    </global>
</config>

Front controller in app/code/local/Cmpreshn/Projects/controllers/ProjectsController.php

<?php

    class Cmpreshn_Projects_ProjectsController extends Mage_Core_Controller_Front_Action {

        public function indexAction(){
            $this->listAction();
        }

        public function listAction(){

            echo "list action called<br>";

            /* get request and save params to object */
            $this->request = Mage::app()->getRequest();

            /* layout overrides for this module in app/design/frontend/default/pmc1/layout/projects.xml */
            $this->loadLayout();

            /* use the education template */
            $this->getLayout()->getBlock("root")->setTemplate("page/pmc_education.phtml");

            /* render the layout */
            $this->renderLayout();

        }

    }

XML updates in app/design/frontend/default/pmc1/layout/projects.xml

<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
    <projects_projects_list>
        <remove name="top.menu"/>
        <reference name="content">
            <block type="page/html" name="page" template="cmpreshn/projects/list.phtml" />
        </reference>
    </projects_projects_list>
</layout>

Template overrides and call to custom block in app/design/frontend/default/pmc1/template/cmpreshn/project/list.phtml

<?php echo __FILE__ . " loaded <br>"; ?>
<?php echo $this->getProjectsList(); ?>

Last but not least, my custom block class in app/code/local/Cmpreshn/Proejcts/Block/List.php

<?php

    class Cmpreshn_Projects_Block_List extends Mage_Core_Block_Template {

        public function _construct() {
            parent::__construct();
            echo "projects list block constructor called<br>";
        } // end constructor

        public function getProjectsList() {
            echo "getProjectsList called <br>";
            return("getProjectsList called");
        }

    } // end class

As I mentioned previously, I am getting the output from the first line of my list.phtml template file, but no output from my custom block method, and no indication that my block is loading (no output from block _construct() method either )

Any help is appreciated. I'm ready to pull my eyes out over this...


change the block type to projects/list in your projects.XML file like this

<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
   <projects_projects_list>
      <remove name="top.menu"/>
      <reference name="content">
         <block type="projects/list" name="page" template="cmpreshn/projects/list.phtml/>
      </reference>
   </projects_projects_list>
</layout>

you may get the output now.