How to set the unit layout attributes? - magento

I'm writing a module for magento 1.9. Help please set the attributes for the
app/design/frontend/rwd/default/layout/kalinin_form.xml:
<?xml version="1.0" ?>
<layout>
<kalininform_index_index>
<reference name="content">
<block type="kalininform/form" template="Kalinin_Form/index.phtml" />
</reference>
</kalininform_index_index>
</layout>
I now have the type attribute set to false.
The problem is that the browser displays a blank page with the content area on localhost/magento3/index.php/form
Here is the rest of the code of the module.
app/design/frontend/rwd/default/template/Kalinin_Form/index.phtml:
<?php
echo('qqqqqqqqqqqqq');
app/code/local/Kalinin/Form/controllers/IndexController.php:
<?php
class Kalinin_Form_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
app/code/local/Kalinin/Form/Block/Form.php:
<?php
class Kalinin_Form_Block_Form extends Mage_Core_Block_Template
{
public function getNewsCollection()
{
Mage::log("Your Log Message");
return true;
}
}
app/code/local/Kalinin/Form/etc/config.xml:
<?xml version="1.0" ?>
<config>
<modules>
<Kalinin_Form>
<version>0.0.1</version>
</Kalinin_Form>
</modules>
<frontend>
<layout>
<updates>
<kalininform>
<file>kalinin_form.xml</file>
</kalininform>
</updates>
</layout>
<routers>
<kalininform>
<use>standard</use>
<args>
<module>Kalinin_Form</module>
<frontName>form</frontName>
</args>
</kalininform>
</routers>
</frontend>
<global>
<blocks>
<Kalinin_Form>
<class>Kalinin_Form_Block</class>
</Kalinin_Form>
</blocks>
</global>
</config>
In general, I have a problem with understanding the attributes into app/design/frontend/rwd/default/layout/kalinin_form.xml
Official documentation is not present. I would be grateful if you explain what's what.

In your app/design/frontend/rwd/default/layout/kalinin_form.xml file, your block attribute type value is wrong. it should be kalinin_form/form.
<?xml version="1.0" ?>
<layout>
<kalininform_index_index>
<reference name="content">
<block type="kalinin_form/form" template="Kalinin_Form/index.phtml" />
</reference>
</kalininform_index_index>
</layout>
Value of type attribute should be matched with blockgroup_name given in config.xml.
Please see, your block group name is Kalinin_Form
<global>
<blocks>
<Kalinin_Form>
<class>Kalinin_Form_Block</class>
</Kalinin_Form>
</blocks>
</global>

Related

Magento 1.9 - Creating a new page not working

I'm trying to create a new page to my module without success. I have created a module with the contents:
app\code\local\CompanyName\Insignias\etc\config.xml
<config>
<modules>
<CompanyName_Insignias>
<version>0.0.1</version>
</CompanyName_Insignias>
</modules>
<frontend>
<routers>
<insignias>
<use>standard</use>
<args>
<module>CompanyName_Insignias</module>
<frontName>insignias</frontName>
</args>
</insignias>
</routers>
<layout>
<updates>
<insignias>
<file>insignias.xml</file>
</insignias>
</updates>
</layout>
</frontend>
<...>
</config>
app\code\local\CompanyName\Insignias\controllers\IndexController.php
<?php
class CompanyName_Insignias_IndexController extends Mage_Core_Controller_Front_Action {
public function indexAction() {
$this->loadLayout();
$this->renderLayout();
}
}
and
app/design/frontend/base/default/layout/insignias.xml
<?xml version="1.0"?>
<layout>
<insignias_index_index>
<reference name="content">
<block type="insignias/index" name="insignias_index" template="insignias/index.phtml" />
</reference>
</insignias_index_index>
</layout>
I have created the index.phtml file at app/design/frontend/base/default/template/insignias/index.phtml with a <?php echo "worked" ?> to test it, but when I try to access domain/index.php/insignias it shows me all the default magento blocks and a blank page in the middle where my echo should appear.
Can someone help me?
edit:
Here is a picture of my screen
There's anything in the log files?
--
Btw...
You need to call your block in the indexController.php before renderLayout()
The call would look something like
$myBlock = $this->getLayout()->createBlock('Mage_Core_Block_Template', 'newpage', array('template' => 'newpage/content.phtml'));
$this->getLayout()->getBlock('content')->append($myBlock);
--
You can find Magento log in /var/log within your root Magento installation
There will usually be two files by default, exception.log and system.log.
app/design/frontend/base/default/template/checkout/onepage/shipping_method/available.phtml
app/etc/modules/AMA_Checkout.xml
<?xml version="1.0"?>
<config>
<modules>
<AMA_Checkout>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Checkout />
</depends>
</AMA_Checkout>
</modules>
</config>
app/code/local/AMA/Checkout/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<AMA_Checkout>
<version>1.0.0</version>
</AMA_Checkout>
</modules>
<global>
<blocks>
<amacheckout>
<class>AMA_Checkout_Block</class>
</amacheckout>
</blocks>
</global>
</config>
app/code/local/AMA/Checkout/Block/Onepage/Shipping/Method/Available.php
<?php
class AMA_Checkout_Block_Onepage_Shipping_Method_Available extends Mage_Checkout_Block_Onepage_Shipping_Method_Available
{
public function _construct()
{
parent::_construct();
$this->setTemplate('amacheckout/checkout/onepage/shipping_method/available.phtml');
}
}
template:
app/design/frontend/default/base/template/amacheckout/checkout/onepage/shipping_method/available.phtml

layout file is not loading in magento custom module

I am trying to load template file from layout in my module but my layout xml file is not adding in config.xml .I tried number of solution but I don't know what mistake I am doing.Please help me and tell me where I am wrong.I added my code below..
IndexController.php
<?php
class Magemodul_Test_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
?>
config.xml
<?xml version="1.0"?>
<config>
<modules>
<Magemodul_Test>
<version>1.0.0</version>
</Magemodul_Test>
</modules>
<frontend>
<routers>
<magemodultest>
<use>standard</use>
<args>
<module>Magemodul_Test</module>
<frontName>test</frontName>
</args>
</magemodultest>
</routers>
<layout>
<updates>
<magemodultest>
<file>test.xml</file>
</magemodultest>
</updates>
</layout>
</frontend>
<global>
<blocks>
<test>
<class>Magemodul_Test_Block</class>
</test>
</blocks>
</global>
</config>
block file Monblock.php
<?php
class Magemodul_Test_Block_Monblock extends Mage_Core_Block_Template
{
public function methodblock()
{
return 'informations about my block !!' ;
}
}
layout xml file test.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<test_index_index>
<reference name="content">
<block type="test/monblock" name="afficher_monbloc" template="test/afficher.phtml">
</reference>
</test_index_index>
</layout>
template file afficher.phtml
<?php
echo $this->getmethodblock();
?>

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();
?>

Show icon on product on each page

I'm using custom block to show my module logo over each product, now since catalog_product_view tag it shows the logo at product details page only, the problem is that I want to show the icon on each page on each product, whether it is home page, product list, detail, etc. how to achieve this using blocks
Here is the code
Module Configuration (app\etc\modules\NS_Mymodule.xml)
<config>
<modules>
<NS_Mymodule>
<active>true</active>
<codePool>community</codePool>
</NS_Mymodule>
</modules>
</config>
Configuration XML (app\code\community\NS\Mymodule\etc\config.xml)
<config>
<modules>
<NS_Mymodule>
<version>1.0.1</version>
</NS_Mymodule>
</modules>
<global>
<helpers>
<Mymodule>
<class>NS_Mymodule_Helper</class>
</Mymodule>
</helpers>
<blocks>
<mymodule>
<class>NS_Mymodule_Block</class>
</mymodule>
</blocks>
</global>
<frontend>
<layout>
<updates>
<mymodule>
<file>mymodule.xml</file>
</mymodule>
</updates>
</layout>
</frontend>
</config>
Block Class ( app\code\community\NS\Mymodule\Block\Showicon.php )
class Ns_Mymodule_Block_Showicon extends Mage_Core_Block_Template
{
public function myfunction()
{
return "Hello tuts+ world";
}
}
Layout XML ( app\design\frontend\rwd\default\layout\mymodule.xml)
<layout version="1.0.1">
<catalog_product_view>
<reference name="product.info">
<block type="mymodule/showicon" as="ns_media" name="mymodule_showicon" template="mymodule/showicon.phtml" />
</reference>
</catalog_product_view>
</layout>
Template File (app\design\frontend\rwd\default\template\mymodule\showicon.phtml)
<h1>SHOW ICON HERE</h1>
and in the app\design\frontend\rwd\default\template\catalog\product\view.phtml
<?php echo $this->getChildHtml('ns_media') ?>
right after
<?php echo $this->getChildHtml('media') ?>

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>

Resources