Search code examples
phphtmlmagento

How to bypass toHtml() To print html tags in Magento


At first let me admit, I'm not a programmer, although I have a lot of experience 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


Solution

  • html_entity_decode did the trick!

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