Magento custom block. Can't get block's file

733 views Asked by At

I'm trying to create a new custom block module. /app/code/local/TutsPlus/Demo/etc/config.xml

<config>
<gllobal>
    <models>
        <demo>
            <class>TutsPlus_Demo_Model</class>
        </demo>
    </models>
    <blocks>
        <demo><class>TutsPlus_Demo_Block</class></demo>
    </blocks>
    <helpers>
        <demo>
            <class>TutsPlus_Demo_Helper</class>
        </demo>
    </helpers>
    <events>
        <demo>
            <type>model</type>
            <class>demo/observer/</class>
            <method>logCustomer</method>
        </demo>
    </events>
</gllobal>

<frontend>
    <routers>
        <tutsplus_demo>
            <use>standard</use>
            <args>
                <module>TutsPlus_Demo</module>
                <frontName>demo</frontName>
            </args>
        </tutsplus_demo>
        <catalog>
            <args>
                <modules>
                    <demo before="Mage_Catalog">TutsPlus_Demo</demo>
                </modules>
            </args>
        </catalog>
    </routers>
    <layout>
        <updates>
            <demo>
                <file>tutsplus.xml</file>
            </demo>
        </updates>
    </layout>
</frontend>

/app/code/local/TutsPlus/Demo/Block/Configurable.php

class TutsPlus_Demo_Block_Configurable extends Mage_Core_Block_Template {

    public function getConfigurableProducts() {
        return 'it works';
    }
}

/app/code/local/TutsPlus/Demo/controllers/config.xml

    class TutsPlus_Demo_IndexController extends Mage_Core_Controller_Front_Action {
public function configurableAction(){
        $this->loadLayout();
        $this->renderLayout();
    }
}

configurable.phtml

<?php
echo 'zzz';
echo $this->getConfigurableProducts();

tutsplus.xml

<layout>
    <tutsplus_demo_index_configurable>
        <reference name="content">
            <!--<block type="page/html" name="demo" template="tutsplus/configurable.phtml" />-->
            <block type="tutsplus_demo/configurable" name="demo_configurable" template="tutsplus/configurable.phtml" />
        </reference>
    </tutsplus_demo_index_configurable>
</layout>

When I use commented line I heve just "zzz", no result of working function getConfigurableProducts. If I use second line I have nothing and file haven't been included.

EDIT 1 My folder structure

my folder structure

template structure

2

There are 2 answers

1
Shyam Ranpara On

Put this code in tutsplus.xml

<layout>
<tutsplus_demo_index_configurable>
    <reference name="content">
        <!--<block type="page/html" name="demo" template="tutsplus/configurable.phtml" />-->
        <block type="demo/configurable" name="demo_configurable" template="tutsplus/configurable.phtml" />
    </reference>
</tutsplus_demo_index_configurable>

Remove following code from your config.xml

  <events>
    <demo>
        <type>model</type>
        <class>demo/observer/</class>
        <method>logCustomer</method>
    </demo>
</events>

Refresh cache and storage and check it.

0
Piotr Zarycki On

if you want to know what exactly action is assigned to layout handle, you can "debug" layout handles.

Please paste these code between

    $this->loadLayout();
    print_r($this->getLayout()->getUpdate()->getHandles());
    $this->renderLayout();

You will see assigned layout handles to controller