2

At first let me admit, I'm not a programmer, although I have a lot of expierence in tweaking small bits of php here and there. Also I'm not very familiar with Magento's ways of coding.

I have this client who wants to add the manufacturer's brandname to the breadcrumb with a link to the brandname in it. We're using layered navigation that's where I got the link from.

The output I get is Home / Categoryname / productname of

<a href="http://linktobrand.html">Brandname</a>

Here in which the html doesn't get rendered because of the breadcrumbs block being echoed with the function toHtml().

Is there anyway I can bypass this?

Here's my code: (the code was put in the view.phtml of product)

//Get current category url
$current_category = Mage::registry('current_category')->getUrl();

//Get brandname
$brandname = Mage::getModel('catalog/product')->load($_product->getId())->getAttributeText('manufacturer');

//Strip .html and add the stuff from the layered navigation to it
$brandurl = str_replace(".html", "/l/". strtolower($brandname) .".html", $current_category);    
$brandnamemurl = "of <a href="" . $brandurl . "">" . $brandname . "</a>";

//breadcrumb stuff
$breadcrumbs = $this->getLayout()->getBlock('breadcrumbs');
$breadcrumbs->addCrumb('manufacturer', array('label'=>$brandnamemurl, 'title'=>$brandname));
echo $this->getLayout()->getBlock('breadcrumbs')->toHtml(); 

http://pastebin.com/csueRX6T

2 Answers 2

1

First, be sure you have the proper configuration in your theme's page.xml file. It should look something like this:

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

Then, call the html:

<?php echo $this->getChildHtml('breadcrumbs') ?>

Now, you should also be sure you have breadcrumbs enabled.

System -> Configuration -> Web -> Default Pages -> Show Breadcrumbs for CMS Pages

Be sure to select your proper Configuration Scope before making changes (top left - Default Config, Main Website, Default Store View, etc.), likely you want Main Website.

You may also want to hunt down your breadcrumbs.phtml file and have a peek at that.

1
  • Thanks for taking the time to answer my question Tim! Although I'm really not sure what you mean since I'm a Magento newbie. About my question though, I'm not sure if you answered it, is it possible or not to bypass the rendering of html AFTER toHtml() is called? I'm gonna try and look into the things you said meanwhile. Thanks again. Commented Jun 2, 2015 at 8:47
0

Wow ok, I wanted to try one more thing and hurray, it worked!

html_entity_decode(); did the trick!

Here's what I did;

//Get current category url
$current_category = Mage::registry('current_category')->getUrl();
//Get brandname
$brandname = Mage::getModel('catalog/product')->load($_product->getId())->getAttributeText('manufacturer'); //get brand name
//Strip .html and add the stuff from the layered navigation to it
$brandurl = str_replace(".html", "/l/". strtolower($brandname) .".html", $current_category);    
$brandnamemurl = "of <a href=\"" . $brandurl . "\">" . $brandname . "</a>";

$breadcrumbs = $this->getLayout()->getBlock('breadcrumbs');
$breadcrumbs->addCrumb('manufacturer', array('label'=>$brandnamemurl, 'title'=>$brandname));

//I Added these two lines
$breadcrumbblock = $this->getLayout()->getBlock('breadcrumbs')->toHtml();  
echo html_entity_decode($breadcrumbblock);

Hopefully someone can make use of this someday maybe.

1
  • Feel free to accept your own anser if it solved your problem Commented Jul 3, 2015 at 9:23

Your Answer

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

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