"getLogoAlt" is not available for content section in Magento

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

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

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

which is displayed 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> 

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

+4
source share
1 answer

"Title" is a block added with an XML layout update.

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

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

 #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 call the method in the template block class. Each template "belongs" to the 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 .

In another template you specify, home.phtml , the following xml layout update is added

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

Its block is the core/template block, which is converted to Mage_Core_Block_Template . This block has no getLogoAlt method. However, like all blocks, it has Magento magic getters and setters. You can β€œset” and β€œget” data properties on Magento blocks as follows

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

even if these methods are not defined in the block. Thus, this means that you can call getLogoAlt on any block without error, but only the header will return a value. If you want to use this value in any template, you can simply call

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

at the top of the template, then use $logo_alt wherever you want.

+8
source

Source: https://habr.com/ru/post/1401451/


All Articles