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...
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With