Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"getLogoAlt" not available for content section in Magento

Tags:

magento

In Magento CE 1.5.1, why is getLogoAlt not available for the content section though it is available for the header section?

Inside the content section of the home page, my theme's home.phtml has

<h1 class="no-display"><?php echo $this->getLogoAlt() ?></h1>

which outputs as

<h1 class="no-display"></h1>

But header.phtml,

<h4><a href="<?php echo $this->getUrl('') ?>" id="logo" style="background-image:url(<?php echo $this->getLogoSrc() ?>)"><strong><?php echo $this->getLogoAlt() ?></strong></a></h4>

properly outputs as

<h4><a href="http://mystore.com/" id="logo" style="background-image:url(http://mystore.com/skin/frontend/mytheme/orange/images/logo.png)"><strong>Buy widgets here!</strong></a></h4>

Puzzled...

like image 634
Gaia Avatar asked Feb 22 '23 03:02

Gaia


1 Answers

The "header section" is a block added with the following layout update XML

<block type="page/html_head" name="head" as="head">

The block's type is page/html_head, which translated to the class Mage_Page_Block_Html_Header. If you look at the class definition, you can see the header.phtml template being set.

#File: app/code/core/Mage/Page/Block/Html/Header.php
public function _construct()
{
    $this->setTemplate('page/html/header.phtml');
}

When you use $this->someMethod() from a template, you're calling a method on the template's block class. Each template "belongs" to a block. If we look at the header class again

#File: app/code/core/Mage/Page/Block/Html/Header.php
public function getLogoAlt()
{
    if (empty($this->_data['logo_alt'])) {
        $this->_data['logo_alt'] = Mage::getStoreConfig('design/header/logo_alt');
    }
    return $this->_data['logo_alt'];
}

we can see the definition of getLogoAlt.

The other template you mentioned, home.phtml, is added with the following layout update xml

<block type="core/template" name="default_home_page" template="cms/default/home.phtml"/>

Its block is a core/template block, which translates to Mage_Core_Block_Template. This block does not have a getLogoAlt method. However, like all blocks, it does have Magento's magic getters and setters. You can "set" and "get" data properties on Magento blocks like this

$this->setFooBar('setting a value for the foo_bar data property');
echo $this->getFooBar();

even if the block doesn't have those methods defined. So, this means you can call getLogoAlt on any block without an error being thrown, but only the header block is going to return a value. If you want that value in any template, you can just call

$logo_alt = Mage::getStoreConfig('design/header/logo_alt');

at the top of your template, and then use $logo_alt wherever you'd like.

like image 151
Alan Storm Avatar answered Feb 28 '23 07:02

Alan Storm