Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Set CMS metas from a block ? 
 
RomainB
Jr. Member
 
Total Posts:  2
Joined:  2009-06-11
 

Hi there,

I have a CMS page from which I include my custom block:

{{block type="news/view"}}

In my block, I am trying to redefine the page title, keywords and description, so I tried overwriting the _prepareLayout() function with the following:

if ($head $this->getLayout()->getBlock('head')) {
     $head
->setTitle('test');
}

But no success, so I tried the following in the _toHtml() function with no luck:

$this->setHeaderTitle('test'); 
$this->setTitle('test');

Can anybody give me a light on this one? I am trying on the title at the moment, but I’d like to effectively change the meta keywords and description as well.

Thanks smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
RomainB
Jr. Member
 
Total Posts:  2
Joined:  2009-06-11
 

Ok I figured out it’s not possible because the block is called after the page has already started loading.

What I did is a very ugly workaround but it did fix my problem, I have overwriten the _prepareLayout() method found in app/code/core/Mage/Cms/Block/Page.php and I just appended at the end:

if($page->getId() == 13)
{
   
// My logic to get the page title
   
$title 'test';
}

$head
->setTitle(isset($title) ? $title $page->getTitle());
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top