0

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...

2 Answers 2

3

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>
1
  • Yupz, that does the trick :)
    – Badger
    Commented Oct 6, 2015 at 17:32
2

You can call logo at any where using call of header block at frontend:

<?php $headerBlock = $this->getLayout()->getBlock('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>
1
  • Tried this as well and works also perfectly
    – Badger
    Commented Oct 6, 2015 at 17:34

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.