layout file is not loading in magento custom module - magento

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

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

How to set the unit layout attributes?

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>

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>

Layout for Magento module

I'm new in Magento and I'm trying to make a layout for a module I've build. I have a simple module and an IndexController which outputs 'Hello World.'(I've use this tutorial).
Now I want to make a layout for that module and I've used this tutorial but it doesn't work. Can someone point me to a tutorial or can explain me how layouts work in Magento?
Thx :)
Here's what I've done so far:
I have a package called 'Andrei' and a module 'Hello World'.
Here is the config.xml for my module:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Andrei_Helloworld>
<version>0.1.0</version>
</Andrei_Helloworld>
</modules>
<frontend>
<routers>
<helloworld>
<use>standard</use>
<args>
<module>Andrei_Helloworld</module>
<frontName>helloworld</frontName>
</args>
</helloworld>
</routers>
</frontend>
</config>
Here is the Andrei_Helloworld module:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Andrei_Helloworld>
<active>true</active>
<codePool>local</codePool>
</Andrei_Helloworld>
</modules>
</config>
And here is my controller:
class Andrei_Helloworld_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
echo 'Hello world';
}
}
This is all I've done so far. The module works properly. And I want a layout for my IndexController. Thx :)
so, there is some stuff missing...
declare the layout update in the your config.xml:
<frontend>
...
<layout>
<updates>
<helloworld>
<file>helloworld.xml</file>
</helloworld>
</updates>
</layout>
...
</frontend>
create the layout xml file, in app/design/frontend/base/default/layout/helloworld.xml and in it you create a reference to your module/controller/action:
<?xml version="1.0"?>
<layout>
<helloworld_index_index>
<reference name="content">
<block type="core/template" name="helloworld" template="helloworld.phtml" />
</reference>
</helloworld_index_index>
</layout>
create the phtml file you've just set as template in your xml layout file, ie app/design/frontend/base/default/template/helloworld.phtml:
this is the content of helloworld.phtml
load and render all this stuff, in your controller's action, replace your echo statement with:
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
disable cache, refresh browser, sit back and enjoy

Resources