I am a Magento beginner and need help with creating a new custom block. Basically I just want the block to show "hello" if it is called.
Module installation xml file, app/etc/modules/MyExtensions_HelloBlock.xml
<?xml version="1.0" encoding="UTF-8"?> <config> <modules> <MyExtensions_HelloBlock> <active>true</active> <codePool>local</codePool> </MyExtensions_HelloBlock> </modules> </config>
Module configuration xml file, app/code/local/MyExtensions/HelloBlock/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?> <config> <modules> <MyExtensions_HelloBlock> <version>0.0.1</version> </MyExtensions_HelloBlock> </modules> <global> <blocks> <helloblock> <class>MyExtensions_HelloBlock_Block</class> </helloblock> </blocks> </global> </config>
Block class, app/code/local/MyExtensions/HelloBlock/Hello.php
<?php class MyExtensions_HelloBlock_Block_Hello extends Mage_Core_Block_Template { public function hello() { echo "hello"; } } ?>
Template file for the block, app/design/frontend/default/default/template/helloblock/hello.phtml
<?php $this->hello(); ?>
Then I call my new block like this in the template "app/design/frontend/venedor/default/template/page/1column.phtml":
echo $this->getLayout()->createBlock('helloblock/hello')->setTemplate('helloblock/hello.phtml')->toHtml();
Result:
Fatal error: Call to a member function setTemplate() on boolean in /app/design/frontend/venedor/default/template/page/1column.phtml on line 58
I was following this tutorial.