Magento – Content block not showing

blocksmodule

I'm trying to set up a custom block module and display it. For this question my namespace is V, module name W.
I've created global config file, V_All.xml, in app/etc/modules/

  <?xml version="1.0"?>
   <config>
    <modules>
     <V_W>
       <active>true</active>
       <codePool>local</codePool>
     </V_W>
    </modules>
   </config>

I've also created module config file, config.xml, in app/code/local/V/W/etc/

 <?xml version="1.0"?>
  <config>
   <modules>
     <V_W>
       <version>1.0</version>
     </V_W>
   </modules>

   <global>
    <blocks>
      <w>
        <class>V_W_Block</class>
      </w>
    </blocks>
   </global>
  </config>

I've created class file for custom block, Yblock.php, at: app/code/local/V/W/Block/Yblock.php

 <?php
  class V_W_Block_Yblock extends Mage_Core_Block_Template
  {  // Methods
  }
  ?>

I've created a template file, Yblock.phtml, to output custom block data in app/design/frontend/Mypackage/Mytheme/template/Z/Yblock.phtml. In it I have:

  <?php echo "Test Custom Block"; ?>

I've tried to display block via local.xml:

 <?xmlversion="1.0"encoding="UTF-8"?>
   <layoutversion="0.1.0">
     <default>
       <reference name="root">
         <reference name="content">
           <block type="w/yblock" name="yblock" template="z/yblock.phtml" before="-"/>
         </reference>
       </reference>
     </default>
   </layout>

However, nothing is displayed on browser. I've gone through my code and cannot find anything to alter. I wonder if anyone could point why "Test Custom Block" is not being displayed. I'll be grateful for all assistance.

Best Answer

The problem is resides in in you layout update xml file. You have your block defined like this.

<block type="w/yblock" name="yblock" template="z/yblock.phtml" before="-"/>

Here the template attribute is wrong. As per your template file name, it's value should beZ/Yblock.phtml instead of z/yblock.phtml. ie block attributes are case-sensitive.

The correct definition would be

<block type="w/yblock" name="yblock" template="Z/Yblock.phtml" before="-"/>

You can also resolve this problem by changing the file name to z/yblock.phtml.ie change the location of file like this : app/design/frontend/Mypackage/Mytheme/template/z/yblock.phtml


Note : Clear all cache after the changes made.