dotty
dotty

Reputation: 41433

Overwriting a page title with Magento

I've looked around for how to do this, but nothing is working.

I have a .phtml file and want to use this to overwrite the current title (which sits between the <title></title> tags).

I found somewhere that $this->getLayout()->getBlock('head')->setTitle("New Title"); was suppose to do it, but that doesn't. However $this->getLayout()->getBlock('head')->getTitle(); correctly return the current title correctly.

Any help will be great

Upvotes: 3

Views: 11829

Answers (4)

studioromeo
studioromeo

Reputation: 1548

I don't think you can do it in the .phtml. I would use the local.xml file and follow this guide.

This allows you to set the title for different pages like so:

<reference name="head">
    <action method="setForcedTitle"><title>Account Dashboard</title></action>
</reference>

Upvotes: 4

shmuli
shmuli

Reputation: 5192

You can do this simply, by editing the page title in the "CMS" configuration in the admin panel. It's extremely simple, no need for any coding.

Upvotes: -1

Bhavesh Godhani
Bhavesh Godhani

Reputation: 378

I don't think you can do it in the .phtml, easy solution here

you have set page tile like "Send email to friend" so open your sendfriend.xml file and set below code.

 <reference name="head">
        <action method="setTitle" translate="title" module="sendfriend"><title>Email to a Friend</title></action>
    </reference>

it's working..

Upvotes: 3

Siva Kumar
Siva Kumar

Reputation: 560

Magento loads head.phtml first. So we cant override the title from another template file.

I had a similar requirement. What i did was below.

<title>
<?php
/*****************Customized For Title***********************/
        $url = $_SERVER['REQUEST_URI']; //Check With url
        $url = parse_url($url, PHP_URL_PATH);
        $url = explode('/',$url);
        $url_key = $url[2]; //Set The url-key           

        $cateUrl = Mage::getModel('catalog/category')->getCollection ()
        ->addAttributeToSelect ('id')
        ->addAttributeToFilter ('url_key',  $url_key) //load the  category
        ->getFirstItem (); //only 1 result ; 

        $catSel = Mage::getModel('catalog/category')->load($cateUrl->entity_id)->getMetaTitle();            

        //If Page title then Update
        if(!empty($catSel))
                 $this->getLayout()->getBlock('head')->setTitle($catSel);

        /*****************Customized For Title***********************/
        echo $this->getTitle() 
?>
</title>

In my case i needed to check the url and if the URL has a pagetitle from category it will overwrite it.

Upvotes: 0

Related Questions