Search code examples
magento

How do I add a new block to my layout in magento 1.9?


I have a beginner question on layouts ...After reading a lot about layouts, i am more confused than where i started. I want to add a banner block that will be displayed on my home page and a few other pages. I decided that it cannot be a part of the header.

I want to add this right below the header. I am trying to create my layout via bootstrap. I see in some themes that this is done inside the cms.xml file and i am not sure why i need to edit that. Clearly, i am confused..

Any help would be appreciated.


Solution

  • Go to your theme

    app/design/frontend/Your-Package/Your-Theme/layout/local.xml
    

    add below code:

    <?xml version="1.0"?>
    <layout version="0.1.0">
       <cms_index_index>
          <reference name="content">
                <block type="core/template" name="banner" before="-"  template="banner/banner.phtml" />
            </reference>
       </cms_index_index>
    </layout>
    

    add banner.phtml file to

    app/design/frontend/Your-Package/Your-Theme/template/banner/banner.phtml
    

    add your banner in above file

    To add a block to any other page replace <cms_index_index> with <routname_controllername_actionname> For example, <catalog_product_view>.