Magento isn't displaying custom block - magento

In my config.xml I have:
<config>
<modules>
<Test_Quickorder>
<version>0.1.0</version>
</Test_Quickorder>
</modules>
<global>
<blocks>
<quickorder>
<rewrite>
<quickorder>Test_Quickorder_Block_Quickorder</quickorder>
</rewrite>
</quickorder>
</blocks>
</global>
<frontend>
<routers>
<quickorder>
<use>standard</use>
<args>
<module>Test_Quickorder</module>
<frontName>quickorder</frontName>
</args>
</quickorder>
</routers>
<layout>
<updates>
<quickorder>
<file>quickorder.xml</file>
</quickorder>
</updates>
</layout>
</frontend>
</config>
In app/code/community/Test/Quickorder/controllers/IndexController.php I have:
<?php
class Test_Quickorder_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout(array('default');
$this->renderLayout();
}
}
In app/design/frontend/base/default/layout/quickorder.xml I have:
<layout version="0.1.0">
<default>
<reference name="top.links">
<action method="addLink" translate="label title">
<label>Quick Order</label>
<url>quickorder</url>
<title>Quick Order</title>
<prepare/>
<urlParams/>
<position>1</position>
</action>
</reference>
</default>
<quickorder_index_index>
<reference name="root">
<action method="setTemplate">
<template>page/1column.phtml</template>
</action>
</reference>
<reference name="content">
<block type="quickorder/quickorder" name="quick" template="quickorder/quickorder.phtml"/>
</reference>
</quickorder_index_index>
</layout>
In app/design/frontend/base/default/template/quickorder/quickorder.phtml I have:
<div class="content">
<p>Hello</p>
</div>
And in app/code/community/Test/Quickorder/Block/Quickorder I have:
<?php
class Test_Quickorder_Block_Quickorder extends Mage_Core_Block_Abstract
{
}
I was expecting "Hello" to show up right in the middle of the page. Instead I get nothing. I know some part of the layout is working because when I navigate to quickorder I get
<body class="quickorder-index-index">
Can anybody point me in the right direction as to where I've gone wrong here?
Thanks in advance for any help/tips/pointers :-)

I haven't examined all your code, but this
class Test_Quickorder_Block_Quickorder extends Mage_Core_Block_Abstract
{
}
should be this
class Test_Quickorder_Block_Quickorder extends Mage_Core_Block_Template
{
}
If you want a block to render a template, it needs to be, or inherit from, Mage_Core_Block_Template.

Related

how call custom module block in template file using layout configration file in magento

friends
i have created custom module ,in which i have crated blocks .i want use this block in template but this is not work.
This is my config file :-
<?xml version="1.0"?>
<config>
<modules>
<CustomModule_SocialLogin>
<version>1.0.0</version>
</CustomModule_SocialLogin>
</modules>
<frontend>
<routers>
<customer>
<args>
<modules>
<CustomModule_SocialLogin before="Mage_Customer">CustomModule_SocialLogin_Customer </CustomModule_SocialLogin>
</modules>
</args>
</customer>
<sociallogin>
<use>standard</use>
<args>
<module>CustomModule_SocialLogin</module>
<frontName>sociallogin</frontName>
</args>
</sociallogin>
</routers>
<layout>
<updates>
<CustomModule_SocialLogin module="CustomModule_SocialLogin">
<file>CustomModule/sociallogin.xml</file>
</CustomModule_SocialLogin>
</updates>
</layout>
</frontend>
<global>
<blocks>
<CustomModule_SocialLogin>
<class>CustomModule_SocialLogin_Block</class>
</CustomModule_SocialLogin>
</blocks>
<models>
<CustomModule_SocialLogin>
<class>CustomModule_SocialLogin_Model</class>
</CustomModule_SocialLogin>
</models>
<helpers>
<CustomModule_SocialLogin>
<class>CustomModule_SocialLogin_Helper</class>
</CustomModule_SocialLogin>
</helpers>
</global>
</config>
My block file -:
class CustomModule_SocialLogin_Block_Qa extends Mage_Core_Block_Template{
public function getText()
{
$name='test';
return $name;
}
}
custom module layout update file :-
<layout version="0.1.0">
<default>
<reference name="content" translate="label">
<block type="custommodule_sociallogin/qa" name="SocialLogin.qa" template="CustomModule/SocialLogin/questionans.phtml" />
</reference>
</default>
</layout>
my template file :-
<?php
echo $this->getText()->toHtml();
//echo $this->getText();
?>
Please help me to solve this error .
You need to correct your module layout file. I have corrected the block type.
<layout version="0.1.0">
<default>
<reference name="content" translate="label">
<block type="sociallogin/qa" name="SocialLogin.qa" template="CustomModule/SocialLogin/questionans.phtml" />
</reference>
</default>
In template file :-
<?php
echo $this->getText();
?>

How to load phtml file in magento admin

app\code\local\Stw\Tree\Block\Adminhtml\Adminblock.php
<?php
class Stw_Tree_Block_Adminhtml_Adminblock extends Mage_Adminhtml_Block_Template
{
public function __construct()
{
parent::__construct();
}
protected function _prepareLayout()
{
return parent::_prepareLayout();
}
public function getHandleUpdates()
{
Zend_Debug::dump($this->getLayout()->getUpdate()->getHandles());
}
}
app\code\local\Stw\Tree\controllers\Adminhtml\CustomController.php
class Stw_Tree_Adminhtml_CustomController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout();
$this->_setActiveMenu('mycustomtab');
$this->renderLayout();
}
}
app\design\adminhtml\default\default\layout\tree.xml
<?xml version="1.0"?>
<layout>
<default>
<reference name="content">
<block type="tree/adminhtml_adminblock" name="tree" template="tree/myform.phtml" />
</reference>
</default>
</layout>
app\code\local\Stw\Tree\etc\config.xml
<?xml version="1.0"?>
<config>
<modules>
<Stw_Tree>
<version>1.0.0</version>
</Stw_Tree>
</modules>
<global>
<helpers>
<stw_tree>
<!-- Helper definition needed by Magento -->
<class>Mage_Core_Helper</class>
</stw_tree>
</helpers>
<blocks>
<stw_tree>
<class>Stw_Tree_Block</class>
</stw_tree>
</blocks>
</global>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<stw_tree before="Mage_Adminhtml">Stw_Tree_Adminhtml</stw_tree>
</modules>
</args>
<layout>
<updates>
<tree>
<file>tree.xml</file>
</tree>
</updates>
</layout>
</adminhtml>
</routers>
</admin>
</config>
I want load myform.phtml in admin section of magento, but nothing is loading. I am not understanding what is wrong in that. please someone tell me changes. myform.phtml contains pure HTML code
As defined block in config.xml as below :-
<blocks>
<stw_tree>
<class>Stw_Tree_Block</class>
</stw_tree>
</blocks>
You need to use same alias to call this block from Layout as below :-
<layout>
<default>
<reference name="content">
<block type="stw_tree/adminhtml_adminblock" name="tree" template="tree/myform.phtml" />
</reference>
</default>
</layout>
I don't believe the layout node should be inside the router note like that in your config.xml file. You should add a new adminhtml node as a sibling to admin, i.e. a direct child of config.
</admin>
<adminhtml>
<layout>
<updates>
<tree>
<file>tree.xml</file>
</tree>
</updates>
</layout>
</adminhtml>
</config>

error 404 in user's my account magento

I am creating a module for creating new tab in User's myaccount. I have successfully added a tab named "My Special Products".
Problem is that when i click on that tab it's redirect to 404 error page. I am not able to getting the problem.
My layout xml(customtabs.xml) code is:
<?xml version="1.0"?>
<layout version="0.1.0">
<customer_account>
<!-- Mage_Review -->
<reference name="customer_account_navigation" before="-" >
<action method="addLink" translate="label" module="customer">
<name>newtab</name>
<url>customer/newtab/</url>
<label>My Special Products</label>
</action>
</reference>
</customer_account>
<customer_account translate="label">
<label>Customer My Special Products</label>
<update handle="customer_account"/>
<reference name="my.account.wrapper">
<block type="customer/newtab_newtab" name="customer_newtab_newtab" template="customer/newtab/newtab.phtml"/>
</reference>
</customer_account>
</layout>
My template page is at template\customer\newtab\newtab.phtml
My config.xml for module "Customtabs" is :
<?xml version="1.0"?>
<config>
<modules>
<Fishpig_Customtabs>
<version>0.1.0</version>
</Fishpig_Customtabs>
</modules>
<global>
<blocks>
<customtabs>
<class>Fishpig_Customtabs_Block</class>
</customtabs>
</blocks>
<models>
<customtabs>
<class>Fishpig_Customtabs_Model</class>
</customtabs>
</models>
<helpers>
<customtabs>
<class>Fishpig_Customtabs_Helper</class>
</customtabs>
</helpers>
</global>
<frontend>
<layout>
<updates>
<customtabs>
<file>Customtabs.xml</file>
</customtabs>
</updates>
</layout>
</frontend>
<adminhtml>
<layout>
<updates>
<customtabs>
<file>customtabs.xml</file>
</customtabs>
</updates>
</layout>
<events>
<catalog_product_save_after>
<observers>
<fishpig_save_product_data>
<type>singleton</type>
<class>customtabs/observer</class>
<method>saveProductTabData</method>
</fishpig_save_product_data>
</observers>
</catalog_product_save_after>
</events>
</adminhtml>
</config>
Any one can help me where is the problem.
You set url for this tab as <url>customer/newtab/</url>
so, you should have controller of newtab somewhere,
First you need to add <routers> part in your module's config.xml, put this in <frontend>.
<routers>
<customtabs>
<use>standard</use>
<args>
<module>Fishpig_Customtabs</module>
<frontName>customtabs</frontName>
</args>
</customtabs>
</routers>
change <url>customer/newtab/</url> to <url>customtabs/newtab</url> in customtabs.xml file.
also put,
<customtabs_newtab_index>
<update handle="customer_account"/>
<reference name="my.account.wrapper">
<block type="customer/newtab_newtab" name="customer_newtab_newtab" template="customer/newtab/newtab.phtml"/>
</reference>
</customtabs_newtab_index>
create a controller at code/local/Fishpig/Customtabs/controllers/NewtabController.php
in that your code should be
class Fishpig_Customtabs_NewtabController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
if(!Mage::getSingleton('customer/session')->isLoggedIn())
{
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account'));
return false;
}
$this->loadLayout();
$this->_initLayoutMessages('customer/session');
$this->getLayout()->getBlock('head')->setTitle($this->__('My Special Products'));
$this->renderLayout();
}
}
Add a block file as app/code/local/Fishpig/Customtabs/Block/Customtabs.php
and put there code,
class Fishpig_Customtabs_Block_Customtabs extends Mage_Core_Block_Template
{
public function _prepareLayout()
{
return parent::_prepareLayout();
}
public function getCustomtabs()
{
if (!$this->hasData('customtabs')) {
$this->setData('customtabs', Mage::registry('customtabs'));
}
return $this->getData('customtabs');
}
}
and change your block type in your customtabs.xml file
<block type="customtabs/customtabs" name="customer_newtab_newtab" template="customer/newtab/newtab.phtml" />

Why is my block not showing?

I don't know why my block isn't showing up. It's not showing up on any page, and I cleared the cache. Can someone help me figure out what I missed? However, the var_dump('test') shows up!
app/design/frontend/default/default/template/justin/head.phtml
testing this block
Justin/Bieber/Block/Sings.php
class Justin_Bieber_Block_Sings extends Mage_Core_Block_Template
{
protected function _construct()
{
parent::_construct();
var_dump("test");
}
}
config.xml
<frontend>
...
<layout>
<updates>
<bieber>
<file>justin.xml</file>
</bieber>
</updates>
</layout>
</frontend>
<global>
<blocks>
<bieber>
<class>Justin_Bieber_Block</class>
</bieber>
</blocks>
...
</global>
app/design/frontend/default/default/layout/justin.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="head">
<block type="bieber/bieber" name="justin_bieber">
<action method="setTemplate">
<template>justin/head.phtml</template>
</action>
</block>
</reference>
</default>
</layout>
In your justin.xml block type should be
<block type="bieber/sings" name="justin_bieber">
In this case "bieber" is your module alias name and "sings" is class name.
Your code seems fine to me.
Regarding justin.xml try to change it to the following:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="head">
<block type="bieber/sings" name="justin_bieber" as="justin_bieber" template="justin/head.phtml" />
</reference>
</default>
</layout>
Let me know if that works!
Symlinks were the problem. Magento won't be able to grab the file if it is in a symlinked directory.
Turn it on!
Magento/Zend not allowing symbolic links
Another thing is to turn on template hints!

Magento 1.6.2 - Problems overriding contacts controller

Ok so I've setup a new module to override the Contacts controller so that I can add a newsletter sign up option to it. My setup is as follows:
/app/code/local/MyNamespace/ContactsPlus/controllers/Contacts/IndexController.php:
<?php
# Controllers are not autoloaded so we will have to do it manually:
require_once 'Mage/Contacts/controllers/IndexController.php';
class MyNameSpace_ContactsPlus_Contacts_IndexController extends Mage_Contacts_IndexController
{
# Overloaded indexAction
public function indexAction() {
# Just to make sure
error_log('Yes, I did it!');
parent::indexAction();
}
}
/app/code/local/MyNamespace/ContactsPlus/etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<mynamespace_ContactsPlus>
<version>0.1.0</version>
</mynamespace_ContactsPlus>
</modules>
<global>
<rewrite>
<mynamespace_contactsplus_contacts_index>
<from><![CDATA[#^/contacts/index/#]]></from>
<to>/contactsplus/contacts_index/</to>
</mynamespace_contactsplus_contacts_index>
<mynamespace_contactsplus_contacts_index>
<from><![CDATA[#^/contacts/#]]></from>
<to>/contactsplus/contacts_index/</to>
</mynamespace_contactsplus_contacts_index>
</rewrite>
</global>
<frontend>
<routers>
<mynamespace_contactsplus>
<use>standard</use>
<args>
<module>mynamespace_ContactsPlus</module>
<frontName>contactsplus</frontName>
</args>
</mynamespace_contactsplus>
</routers>
</frontend>
</config>
/app/etc/modules/MyNamespace_All.xml:
<?xml version="1.0"?>
<config>
<modules>
<MyNameSpace_ContactsPlus>
<active>true</active>
<codePool>local</codePool>
</MyNamespace_ContactsPlus>
</modules>
</config>
THe module appears in the admin modules list and it has produced the following error on my /contacts/ page:
Fatal error: Call to a member function setFormAction() on a non-object in /srv/www/foo.com/app/code/core/Mage/Contacts/controllers/IndexController.php on line 54
That's this line:
$this->getLayout()->getBlock('contactForm')->setFormAction( Mage::getUrl('*/*/post') );
I'm not sure where to go from here though, a guess is that it can't set the form action on whatever is being returned from Mage::getUrl('//post') but I'm clutching at straws tbh.
Any help of advice would be greatly appreciated!
Ok after much research, help and general frustration here is how I got it working:
First up, my module directory is set out as follows (note the caps on the directories):
/app/code/local/MyNamespace/ContactsPlus/etc/
config.xml
/app/code/local/MyNamespace/ContactsPlus/controllers/
IndexController.php
/app/code/local/MyNamespace/ContactsPlus/Helper/
Data.php
Now for the config files:
/app/code/local/MyNamespace/ContactsPlus/etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<MyNameSpace_ContactsPlus>
<version>0.1.0</version>
</MyNameSpace_ContactsPlus>
</modules>
<frontend>
<routers>
<!-- Creates route to my module via /contactsplus/ - I used this for testing -->
<contactsplus>
<use>standard</use>
<args>
<module>MyNameSpace_ContactsPlus</module>
<frontName>contactsplus</frontName>
</args>
</contactsplus>
<!-- Sets Mage_Contacts route to MyNameSpace_ContactsPlus -->
<contacts>
<args>
<modules>
<MyNameSpace_ContactsPlus before="Mage_Contacts">MyNameSpace_ContactsPlus</MyNameSpace_ContactsPlus>
</modules>
</args>
</contacts>
</routers>
<!-- Sets layout config file (essential for this to work) -->
<layout>
<updates>
<contactsplus>
<file>contactsplus.xml</file>
</contactsplus>
</updates>
</layout>
</frontend>
<global>
<!-- Sets a helper class for the module, when overriding contacts this is also essential. -->
<helpers>
<contactsplus>
<class>MyNameSpace_ContactsPlus_Helper</class>
</contactsplus>
</helpers>
</global>
</config>
/app/code/local/MyNamespace/ContactsPlus/controllers/Contacts/IndexController.php:
<?php
# Controllers are not autoloaded so we will have to do it manually:
require_once 'Mage/Contacts/controllers/IndexController.php';
class MyNameSpace_ContactsPlus_IndexController extends Mage_Contacts_IndexController
{
# Overloaded indexAction
public function indexAction() {
# Just to make sure
//die('Yes, I did it!');
parent::indexAction();
}
}
/app/code/local/MyNamespace/ContactsPlus/Helper/Data.php:
<?php
class MyNameSpace_ContactsPlus_Helper_Data extends Mage_Core_Helper_Abstract
{
}
/app/etc/modules/MyNamespace_ContactsPlus.xml:
<?xml version="1.0"?>
<config>
<modules>
<MyNameSpace_ContactsPlus>
<active>true</active>
<codePool>local</codePool>
</MyNameSpace_ContactsPlus>
</modules>
</config>
/app/design/frontend/mythemepackage/mytheme/layout/contacts.xml:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="footer_links">
<!-- <action method="addLink" translate="label title" module="contacts" ifconfig="contacts/contacts/enabled"><label>Contact Us</label><url>contacts</url><title>Contact Us</title><prepare>true</prepare></action>
--></reference>
</default>
<contacts_index_index translate="label">
<!-- had to comment this out in order to prevent a duplicate form issue, if anyone has a better method for this then I'd love to here it :)
<label>Contact Us Form</label>
<reference name="head">
<action method="setTitle" translate="title" module="contacts"><title>Contact Us</title></action>
</reference>
<reference name="root">
<action method="setTemplate"><template>page/2columns-right.phtml</template></action>
<action method="setHeaderTitle" translate="title" module="contacts"><title>Contact Us</title></action>
</reference>
<reference name="content">
<block type="core/template" name="contactForm" template="contacts/form.phtml"/>
</reference>
-->
</contacts_index_index>
<!-- added this to rewrite contacts handle to the new modules handle -->
<contacts_index_index>
<update handle="contactsplus_index_index"/>
</contacts_index_index>
</layout>
/app/design/frontend/mythemepackage/mytheme/layout/contactsplus.xml:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="footer_links">
<!-- <action method="addLink" translate="label title" module="contacts" ifconfig="contacts/contacts/enabled"><label>Contact Us</label><url>contacts</url><title>Contact Us</title><prepare>true</prepare></action>
--></reference>
</default>
<contactsplus_index_index translate="label">
<label>Contact Us Form</label>
<reference name="head">
<action method="setTitle" translate="title" module="contactsplus"><title>Contact Us</title></action>
</reference>
<reference name="root">
<action method="setTemplate"><template>page/2columns-right.phtml</template></action>
<action method="setHeaderTitle" translate="title" module="contactsplus"><title>Contact Us</title></action>
</reference>
<reference name="content">
<block type="core/template" name="contactForm" template="contactsplus/custom_form.phtml"/>
</reference>
</contactsplus_index_index>
</layout>
I also made a copy of /app/design/frontend/mythemepackage/mytheme/template/contacts/form.phtml and placed it in /app/design/frontend/mythemepackage/mytheme/template/contactsplus/ and then modified it to suit my requirements.
Resources I found particularly useful during this process were google, IRC #magento and
http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/custom_module_with_custom_database_table
http://alanstorm.com
Hope this helps someone else at some point.
Now it's onto adding a newsletter sign up option to my new form!

Resources