How to Use Logo in Custom Magento Module – Magento 1.9

magento-1.9module

So I have created a custom module that requires the insertion of the Magento logo. Module logic is complete and working as it should. In my .phtml file I need to call for the template logo and I'm trying to accomplish this by calling the standard code used in the Magento base theme:

<h1 class="logo">
 <strong><?php echo $this->getLogoAlt() ?></strong>
  <a href="<?php echo $this->getUrl('') ?>" title="<?php echo $this->getLogoAlt() ?>" class="logo"><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></a>
</h1>

This does not working and I'm clearly missing something here. Should extend a class or something to get this working? Funny thing is that I do get the "href" returned…

Best Answer

Both the functions getLogoSrc() and getLogoAlt() are from block Mage_Page_Block_Html_Header

So if your template file is not using this block object it will not work.

For that you will need to take object of Mage_Page_Block_Html_Header class.

You can call it like

<?php $headerBlock = $this->getLayout()->getBlockSingleton('page/html_header');?>

<h1 class="logo">
 <strong><?php echo $headerBlock ->getLogoAlt() ?></strong>
  <a href="<?php echo $this->getUrl('') ?>" title="<?php echo $headerBlock->getLogoAlt() ?>" class="logo"><img src="<?php echo $headerBlock->getLogoSrc() ?>" alt="<?php echo $headerBlock->getLogoAlt() ?>" /></a>
</h1>
Related Topic