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.
-
z/yblock.phtml should be Z/Yblock.phtml as you file/folder name start with uppercaseAmit Bera– Amit Bera ♦2015年10月29日 03:58:25 +00:00Commented Oct 29, 2015 at 3:58
1 Answer 1
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.
-
"As per your template file name, it's value should beZ/Yblock.phtml instead of z/yblock.phtml. ie block attributes are case-sensitive" I've tried that but it does not solve problem. Any thoughts?raydona– raydona2015年11月01日 14:32:18 +00:00Commented Nov 1, 2015 at 14:32
-
@raydona there may be multiple cause for this. you layout update xml file may not working. did you clear your cache after changes made?Rajeev K Tomy– Rajeev K Tomy2015年11月01日 14:36:10 +00:00Commented Nov 1, 2015 at 14:36
-
Hi, I've cleared cache by deleting everything from the /var/cache directory. One thing I failed to mention is that in: System -> Configuration -> Advanced and in "Disable Modules Output" listing, I do not see my module listed. It seems the module is not being registered.raydona– raydona2015年11月03日 20:34:54 +00:00Commented Nov 3, 2015 at 20:34
-
@raydona put your site in develper mode and look for any log errors. Most probably you can find out an answer thereRajeev K Tomy– Rajeev K Tomy2015年11月04日 01:03:57 +00:00Commented Nov 4, 2015 at 1:03