Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Layout for a custom module
 
benippon-francois
Member
 
Total Posts:  51
Joined:  2009-01-15
 

Hello,

I wrote a module to list some products (with the default list.phtml template) and I try to access it by a ‘clean’ url (until now I have a cms page including the block, so example.com/listing?series=name).
I try to have example.com/series/name, so I create a controller as explained in http://stackoverflow.com/questions/576908/how-does-magento-code-work, with

<?php
class BeNippon_CustomListing_IndexController
   
extends Mage_Core_Controller_Front_Action
{
   
public function indexAction() {
      $this
->loadLayout();
      
$this->_initLayoutMessages('catalog/session');

      
$this->getLayout()->getBlock('content')->append(
         
$this->getLayout()->createBlock('catalog/product_listing')
      );

      
$this->getLayout()->getBlock('head')->setTitle($this->__('Listing'));

      
$this->renderLayout();
   
}
}

as controller,

<?xml version="1.0"?>
<layout>
   <
series>
      <
reference name="root">
         <
action method="setTemplate"><template>page/3columns.phtml</template></action>
      </
reference>
      <
reference name="content">
         <
block type="catalog/product_listing" name="series.list" template="catalog/product/list.phtml"/>
      </
reference>
   </
series>
</
layout>

as layout (named listing.xml)

and

<frontend>
      <
routers>
         <
series>
            <use>
standard</use>
               <
args>
                  <
module>BeNippon_CustomListing</module>
                  <
frontName>series</frontName>
               </
args>
         </
series>
      </
routers>
      <
layout>
         <
updates>
            <
customLinsting>
               <
file>listing.xml</file>
            </
customLinsting>
         </
updates>
      </
layout>
   </
frontend>
in my config.xml.

I have a magento page but nothing in the ‘content’ part… But I know the controller is lanched because I have Listing in the title bar.
...
Do someone see the mistake, please ? ^^’

Thank you smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
Bojan Hrnkas
Member
 
Total Posts:  51
Joined:  2008-04-15
 

Same problem here. It seems that layout is not being rendered. My magento version is 1.3.1, and I created my module using Module Creator.
Anyone has idea?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Bojan Hrnkas
Member
 
Total Posts:  51
Joined:  2008-04-15
 

I just found out that layout.xml is ok, because if I put core/template for the content block it is fine, but if I put mymodule/mymodule as the content block, it shows nothing. Block is derived from Mage_Core_Block_Template.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Bojan Hrnkas
Member
 
Total Posts:  51
Joined:  2008-04-15
 

Solved!

The name of my block was Mycompany_MyModule_Block_MyModule, but magento was looking for Mycompany_MyModule_Block_Mymodule (notice last m is not capital). After I changed the name of my Block (and the filename from MyModule.php to Mymodule.php), it worked nicely.

What we learn from this: try to avoid module names with multiple capital letters.

 
Magento Community Magento Community
Magento Community
Magento Community
 
benippon-francois
Member
 
Total Posts:  51
Joined:  2009-01-15
 

Well, with something like

<global>
      <
models>
         <
modulename>
            <class>
Blabla_YourModuleName_Model</class>
         </
modulename>
      </
models>
   </global>
you can avoid this problem in fact. Same thing for the blocks.

But of course it is always a good idea to have every time the same name pattern.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top