2

I want to display the category breadcrumb in my custom modules product details page phtml file as:

Home/My Module/Category/Product name

In my

\app\design\frontend\base\default\template\magenshop\recipe\view.phtml

Is this the right way of adding in phtml file?

<?php  $breadcrumbs = $this->getLayout()->getBlock('breadcrumbs');
          $breadcrumbs->addCrumb('home', array(
              'label'=>Mage::helper('catalog')->__('Home'),
              'title'=>Mage::helper('catalog')->__('Go to Home Page'),
              'link'=>Mage::getBaseUrl()
          ));
           $breadcrumbs->addCrumb('recipes', array(
              'label'=>Mage::helper('catalog')->__('Recipes'),
              'title'=>Mage::helper('catalog')->__('Go to Recipes Page'),
              'link'=> Mage::getBaseUrl().'recipes/' //  Module Url
          ));
          $breadcrumbs->addCrumb('category', array(
              'label'=>Mage::helper('catalog')->__($cat->getTitle()),
              'title'=>Mage::helper('catalog')->__($cat->getTitle()),
              'link'=> $CategoryUrl //  Category Url
          ));
    echo $this->getLayout()->getBlock('breadcrumbs')->toHtml();
  ?>

I also added in my modules layout file as:

\app\design\frontend\base\default\layout\magenshop\recipe.xml

<reference name="root">
        <action method="unsetChild"><alias>breadcrumbs</alias></action>
        <block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs">
            <action method="addCrumb">
                <crumbName>Home</crumbName>
                <crumbInfo><label>Home</label><title>Home</title><link>/</link></crumbInfo>
            </action>
            <action method="addCrumb">
                <crumbName>Parent Page</crumbName>
                <crumbInfo><label>Parent Page</label><title>Parent Page</title><link>/Parent Page link</link></crumbInfo>
            </action>
            <action method="addCrumb">
                <crumbName>Current Page</crumbName>
                <crumbInfo><label>Current Page</label><title>Current Page</title></crumbInfo>
            </action>
        </block>
    </reference>

But there is no output of any crumbs

1 Answer 1

1

Try below code:

public function indexAction(){
    $this->loadLayout();
    $breadcrumbs = $this->getLayout()->getBlock('breadcrumbs');

    $breadcrumbsBlock->addCrumb('home', array(
        'label'=>Mage::helper('catalog')->__('Home'),
        'title'=>Mage::helper('catalog')->__('Go to Home Page'),
        'link'=>Mage::getBaseUrl()
    ));

    $breadcrumbsBlock->addCrumb('my_module', array(
        'label'=>Mage::helper('catalog')->__('My Module'),
        'title'=>Mage::helper('catalog')->__('My Module'),
        'link'=> $customerLink //  Module Url
    ));

    $breadcrumbsBlock->addCrumb('category', array(
        'label'=>Mage::helper('catalog')->__($CategoryName),
        'title'=>Mage::helper('catalog')->__($CategoryName),
        'link'=> $CategoryUrl //  Category Url
    ));

    $breadcrumbsBlock->addCrumb('product', array(
        'label'=>Mage::helper('catalog')->__($ProductName),
        'title'=>Mage::helper('catalog')->__($ProductName),
        'link'=> $ProductUrl //  Product Url
    ));

    $title = array(Mage::helper('catalog')->__('My Module') , $CategoryName ,$ProductName );
    if ($headBlock = $this->getLayout()->getBlock('head')) {
        $headBlock->setTitle(join(' ', $title));
    }
}
1
  • Have updated the answer @Amit, need to know how to get the URL for each product and display it in page title
    – Sushivam
    Dec 25, 2016 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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