3

I followed this tutorial to create the custom block in magento

http://www.gravitywell.co.uk/blog/post/how-to-creating-your-own-custom-block-in-magento

But nothing is showed when I open up home page or any other page. I have searched alot on web but unable to solve the issue.

The above tutorial did not mention where to create layout.xml file but I have created it at:

app\design\frontend\gravitywell\example\layout\layout.xml

It has just following code:

<block type="gravitywellexample/menu" name="menu" as="menu" template="gravitywell/menu.phtml" />

Any help will be highly appreciated.

Thanks in advance.

Here is local.xml at app\design\frontend\gravitywell\example\layout:

<?xml version="1.0"?>
 <layout version="0.1.0">
    <default>
        <reference name="right">
            <block type="gravitywellexample/menu" name="menu" as="menu" template="gravitywell/menu.phtml" />
        </reference>
    </default>
</layout>

This is config.xml at app\code\local\Gravitywell\Example\etc:

<?xml version="1.0"?>
 <config>
 <modules>
    <Gravitywell_Example>
        <version>0.1.0</version>
    </Gravitywell_Example>
 </modules>
    <global>
    <blocks>
        <gravitywellexample>
            <class>Gravitywell_Example_Block</class>
        </gravitywellexample>
    </blocks>
</global>

</config>

Here is menu.phtml at app\design\frontend\gravitywell\example\template\gravitywell:

Hello Sir

  • try to rename layout.xml to local.xml – Aboodred1 Apr 30 '14 at 16:20
  • To get the full picture we would need to see your module's config.xml, layout.xml and the .phtml that your child is being called in. – Steve Robbins Apr 30 '14 at 16:38
  • Required code added – MFI Apr 30 '14 at 20:17
2

Nothing wrong with the tutorial that you followed except that it does not mention what layout.xml means.

Anyways, in order for you to solve your issue try to follow the following steps:

  • Make sure your new Magento extension is enabled by going to: admin -> System -> Advanced -> Advanced tab -> Disabled Modules Output
  • Make sure to clear Magento cache if its enabled. Flush magento cache from here: admin -> System -> Cache Management
  • Create local.xml file in this folder app\design\frontend\gravitywell\example\layout\local.xml
  • Place this block <block type="gravitywellexample/menu" name="menu" as="menu" template="gravitywell/menu.phtml" /> under any existing block as the following sample:

local.xml example

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="left">
            <block type="gravitywellexample/menu" name="menu" as="menu" template="gravitywell/menu.phtml" />
        </reference>
    </default>
</layout>

You can replace <reference name="left"> with <reference name="right"> or <reference name="header"> depends on where you want to place your new block.

  • Finally, make sure you change Magento design package to gravitywell, design template to example and layout to example from admin -> System -> General -> Design
|improve this answer|||||
  • I have renamed layout.xml to local.xml but nothing happened. Secondly, I also tried the solution of Aboodred1 but it also does not solve the problem.. – MFI Apr 30 '14 at 17:25
  • Here is local.xml at app\design\frontend\gravitywell\example\layout\local.xml: <?xml version="1.0"?> <layout version="0.1.0"> <default> <reference name="right"> <block type="gravitywellexample/menu" name="menu" as="menu" template="gravitywell/menu.phtml" /> </reference> </default> </layout> – MFI Apr 30 '14 at 17:27
  • @MFI did you add any content in menu.phtml file or you left it empty? – Aboodred1 Apr 30 '14 at 17:30
  • @MFI also did you change magento package and theme to gravitywell/example? – Aboodred1 Apr 30 '14 at 17:34
  • Yes I have added h1 heading in menu.phtml – MFI Apr 30 '14 at 17:35
0

There are two options to include a new layout.xml file:

local.xml

local.xml in design/frontend/<yourpackage>/<yourtheme>/layout is loaded automatically, therefore the tipp by Aboodred should solve your problem

This solution is normally used to add specific blocks to your layout, independant from an extension.

module layout xml

If you want to include your own layout.xml inside your module with your own name, you have to define it in <Company>/<Module>/etc/config.xml, like this:

<config>
  <frontend>
    <layout>
      <updates>
        <mymodule> <!-- this node name needs to be unique through out all config.xml files -->
          <file>mymodule.xml</file>
        </mymodule>
      </updates>
    </layout>
  </frontend>
</config>

More background

Your layout files are loaded here: \Mage_Core_Model_Layout_Update::getFileLayoutUpdatesXml, the local.xml is loaded at least.

|improve this answer|||||
  • I think your answer is a little bit advance ;) – Aboodred1 Apr 30 '14 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.