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

Problem with the custom block in custom module
 
NewFolder
Jr. Member
 
Total Posts:  13
Joined:  2008-11-14
 

I have my custom module called Mayerwin. I want to include my own custom menu to the pages. But no success.

Here is what I am doing:

1) Created the following file \app\design\frontend\default\mycustom\template\custom\main_menu.phtml with the content:

THIS MY COOL TEST

2) Added the following lines to the <default> tag in the file \app\design\frontend\default\mycustom\layout\page.xml

<block type="custom/block_mainmenu" name="my_main_menu" as="my_main_menu" template="custom/main_menu.phtml" />

3) Created file \app\code\local\Mayerwin\Custom\Block\MainMenu.php

<?php
class Mayerwin_Custom_Block_MainMenu extends Mage_Core_Block_Template
{
  
protected function _someTest()
  
{
     
return 'Hello';
  
}
}

4) Try to get the block in the template

<?php
print '--->'.$this->getChildHtml('my_main_menu').'<---';
?>

What am I doing wrong? Please help!

 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

For step 2, try this instead:

<block type="custom/mainmenu" name="my_main_menu" as="my_main_menu" template="custom/main_menu.phtml" />

Your config.xml needs to be correct as well, but you didn’t post it so I cannot validate it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
NewFolder
Jr. Member
 
Total Posts:  13
Joined:  2008-11-14
 

Thank you for your reply. I’ve changed the type as you suggested but it still does not work

This is my config.xml file

<?xml version="1.0"?>
<config>
  <global>
    <
blocks>
      <
mayerwin_custom>
        <class>
Mayerwin_Custom_Block</class>
      </
mayerwin_custom>
    </
blocks>    
  </global>
</
config>
 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

Well, you are telling Magento to use the ‘mayerwin_custom’ alias to get your blocks, then you try to retrieve the blocks with the ‘custom’ alias.

use this:

<block type="mayerwin_custom/mainmenu" name="my_main_menu" as="my_main_menu" template="custom/main_menu.phtml" /
 
Magento Community Magento Community
Magento Community
Magento Community
 
NewFolder
Jr. Member
 
Total Posts:  13
Joined:  2008-11-14
 

Still the same :(

Does magento know that this is a block? This code does not work too:

<block type="mayerwin_custom/block_mainmenu" name="my_main_menu" as="my_main_menu" template="custom/main_menu.phtml" />

Also is it ok if I put the <block> tag to the <default> one? Maybe I should put it somewhere else?

 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

The more detail you provide, the better help you’ll get.  Can you post your config.xml and the layout XML file you are editing?

 
Magento Community Magento Community
Magento Community
Magento Community
 
NewFolder
Jr. Member
 
Total Posts:  13
Joined:  2008-11-14
 

Here are my files:

app\code\local\Mayerwin\Custom\etc\config.xml

<?xml version="1.0"?>
<config>
  <global>
    <
blocks>
      <
mayerwin_custom>
        <class>
Mayerwin_Custom_Block</class>
      </
mayerwin_custom>
    </
blocks>    
  </global>
</
config>

app\design\frontend\default\mycustom\layout\page.xml

<?xml version="1.0"?>
<layout version="0.1.0">
<!--
Default 
layoutloads most of the pages
-->

    <default>
        <
block type="page/html" name="root" output="toHtml" template="page/3columns.phtml">

            <
block type="page/html_head" name="head" as="head">
                <
action method="addJs"><script>prototype/prototype.js</script></action>
                <
action method="addJs" ifconfig="dev/js/deprecation"><script>prototype/deprecation.js</script></action>
                <
action method="addJs"><script>prototype/validation.js</script></action>
                <
action method="addJs"><script>scriptaculous/builder.js</script></action>
                <
action method="addJs"><script>scriptaculous/effects.js</script></action>
                <
action method="addJs"><script>scriptaculous/dragdrop.js</script></action>
                <
action method="addJs"><script>scriptaculous/controls.js</script></action>
                <
action method="addJs"><script>scriptaculous/slider.js</script></action>
                <
action method="addJs"><script>varien/js.js</script></action>
                <
action method="addJs"><script>varien/form.js</script></action>
                <
action method="addJs"><script>varien/menu.js</script></action>
                <
action method="addJs"><script>mage/translate.js</script></action>
                <
action method="addJs"><script>mage/cookies.js</script></action>
                <
action method="addCss"><stylesheet>css/reset.css</stylesheet></action>
                <
action method="addCss"><stylesheet>css/boxes.css</stylesheet></action>
                <
action method="addCss"><stylesheet>css/clears.css</stylesheet></action>
                <
action method="addCss"><stylesheet>css/menu.css</stylesheet></action>
                <
action method="addCss"><stylesheet>trainwreck/style.css</stylesheet></action>
                <
action method="addItem"><type>skin_css</type><name>trainwreck/ie6.css</name><params/><if>IE 6</if></action>
                
                <
action method="addItem"><type>skin_css</type><name>css/iestyles.css</name><params/><if>IE</if></action>
                <
action method="addItem"><type>skin_css</type><name>css/ie7.css</name><params/><if>IE 7</if></action>
                <
action method="addItem"><type>skin_css</type><name>css/ie7minus.css</name><params/><if>lt IE 7</if></action>

                <!--<
action method="addItem"><type>js</type><name>lib/ds-sleight.js</name><params/><if>lt IE 7</if></action>-->
                <
action method="addItem"><type>js</type><name>varien/iehover-fix.js</name><params/><if>lt IE 7</if></action>

                <
action method="addCss"><stylesheet>css/print.css</stylesheet><params>media="print"</params></action>
            </
block>

            <
block type="page/html_header" name="header" as="header">
                <
block type="page/template_links" name="top.links" as="topLinks"/>
                <
block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
                <
block type="core/text_list" name="top.menu" as="topMenu"/>
            </
block>

            <
block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs"/>

            <
block type="core/text_list" name="left" as="left"/>

            <
block type="core/messages" name="global_messages" as="global_messages"/>
            <
block type="core/messages" name="messages" as="messages"/>

            <
block type="core/text_list" name="content" as="content"/>

            <
block type="core/text_list" name="right" as="right"/>

            <
block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">
                <
block type="page/switch" name="store_switcher" as="store_switcher" template="page/switch/stores.phtml"/>
                <
block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml"/>
            </
block>

            <
block type="core/text_list" name="before_body_end" as="before_body_end"/>            
        </
block>

        <
block type="core/profiler" output="toHtml"/>
       
        <
block type="mayerwin_custom/block_mainmenu" name="my_main_menu" as="my_main_menu" template="custom/main_menu.phtml" />
    </default>
</
layout>
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top