How to add breadcrumb in magento

Sunday, September 23, 2012
Breadcrumb is necessary for making website pages user navigation friendly. It can be printed out in any of the php or phtml pages by below code: We can also add our own breadcrumbs as per our requirements in our custom module.A method defined in mage "Mage_Page_Block_Html_Breadcrumbs" Class.We can use it to add crumb:
addCrumb ($crumbName, $crumbInfo, $after=false)
There are two ways to add crumb i.e. one by xml layout and another by using code:
By using code we can add breadcrumb like this:
$breadcrumbs = $this->getLayout()->getBlock('breadcrumbs');
$breadcrumbs->addCrumb('home',array('label'=>Mage::helper('cms')->__('Home'), 'title'=>Mage::helper('cms')->__('Home Page'),
'link'=>Mage::getBaseUrl()));
$breadcrumbs->addCrumb('Fruits', array('label'=>'Fruits',
'title'=>'All Fruits',
'link'=>'http://magento.com/moduleName/fruits'));

$breadcrumbs->addCrumb('types', array('label'=>'Apple',
'title'=>'Apple'));

echo $this->getLayout()->getBlock('breadcrumbs')->toHtml();
By using layout xml,for example,we want to add crumb in a custom about us page:
<aboutus_index_index translate="label">
             <reference name="breadcrumbs">
                    <action method="addCrumb">
                             <name>aboutus</name>
                             <params>
                                     <label>AboutUs</label>
                                     <title>AboutUs</title>
                                     <link> aboutus.html</link>
                             </params>
                     </action>
             </reference>
 </aboutus_index_index>
If you have any further queries,please feel free to comment on it.

1 comments:

  1. Jay Yeoman said...:

    I remember those moment while I'm eating bread and breadcrumbs were falling on my feet. Even a small non-sense move of every particles on this world could highly contribute in the development human business and so with the development of human's living in the world.

Post a Comment