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

Display Page Title on all pages--Not just cms
 
valerie.wininger
Jr. Member
 
Total Posts:  11
Joined:  2008-08-01
 

I have a div in 3column.phtml where I want to display part of the page title on every page of my site.  Right now, I’m using the following code which only works on the cms pages (except for my blog page which doesn’t work either):

<?php echo Mage::getSingleton('cms/page')->getTitle() ?>

However, on every other page, nothing shows up--Product pages, RSS Feed page, Checkout, etc.  I have searched high and low and I can’t find anything on how to do this.  I don’t want this to output the store name, just the text that follows that.  Can someone please help??

 
Magento Community Magento Community
Magento Community
Magento Community
 
joyously
Guru
 
Total Posts:  447
Joined:  2008-08-21
 

Your code only works on CMS pages because that’s the object you are calling it on.
I did a search for getTitle and found this:

Searching for: function getTitle
Mage\Adminhtml\Block\Tax\Rate\Title
.php(42): public function getTitles()
Mage\Adminhtml\Block\Widget\Accordion\Item.php(54): public function getTitle()
Mage\Core\Block\Html\Select.php(85): public function getTitle()
Mage\Customer\Block\Address\Edit.php(61): public function getTitle()
Mage\Page\Block\Html\Head.php(211): public function getTitle()
Mage\Payment\Model\Method\Abstract.php(380): public function getTitle()
Mage\Tax\Model\Calculation\Rate.php(80): public function getTitleModel()
Mage\Tax\Model\Calculation\Rate.php(88): public function getTitles()
Found 8 occurrence(sin 7 file(s)

The one that looks like it would give you what you want is in Page/Block/Html/Head.php . That would be in every page. But it likely doesn’t have anything but the default value in a lot of pages (from what I’ve seen, a lot of pages don’t set the title to anything useful).

 
Magento Community Magento Community
Magento Community
Magento Community
 
valerie.wininger
Jr. Member
 
Total Posts:  11
Joined:  2008-08-01
 

Yeah, I saw that code last night also, but when I just use the code

<?php echo $this->getTitle() ?>

which is what is already pulling the title on every page (within the <title> tag), I get nothing on any of the pages, cms or otherwise.  Does this make sense?  I appreciate your help so much--I’m stuck!

 
Magento Community Magento Community
Magento Community
Magento Community
 
joyously
Guru
 
Total Posts:  447
Joined:  2008-08-21
 

If your code was in the head template, it would work fine. But you’re in 3columns.phtml which is not listed in the search results for the getTitle function. So which one is it calling?
To be sure you were calling the right one you could try

<?php echo Mage::getSingleton('html/head')->getTitle() ?>
I have no idea if that would work, but at the point you are calling it, the $this pointer is not pointing to the part with the information. You need one of its children.
 
Magento Community Magento Community
Magento Community
Magento Community
 
valerie.wininger
Jr. Member
 
Total Posts:  11
Joined:  2008-08-01
 

This made sense to me, but when I tried replacing

<?php echo Mage::getSingleton('cms/page')->getTitle() ?>
line with
<?php echo Mage::getSingleton('html/head')->getTitle() ?>

I got the following error: 

Warning: include(Mage/Html/Model/Head.php) [function.include]: failed to open stream: No such file or directory in /homepages/28/d214479546/htdocs/scottyvalentine/new_design/app/code/core/Mage/Core/functions.php on line 73
Trace:
#0 /homepages/28/d214479546/htdocs/scottyvalentine/new_design/app/code/core/Mage/Core/functions.php(73): mageCoreErrorHandler(2, ‘include(Mage/Ht...’, ‘/homepages/28/d...’, 73, Array)
#1 /homepages/28/d214479546/htdocs/scottyvalentine/new_design/app/code/core/Mage/Core/functions.php(73): __autoload()
#2 [internal function]: __autoload(’Mage_Html_Model...’)
#3 /homepages/28/d214479546/htdocs/scottyvalentine/new_design/app/code/core/Mage/Core/Model/Config.php(720): class_exists(’Mage_Html_Model...’)
#4 /homepages/28/d214479546/htdocs/scottyvalentine/new_design/app/Mage.php(314): Mage_Core_Model_Config->getModelInstance(’html/head’, Array)
#5 /homepages/28/d214479546/htdocs/scottyvalentine/new_design/app/Mage.php(328): Mage::getModel(’html/head’, Array)
#6 /homepages/28/d214479546/htdocs/scottyvalentine/new_design/app/design/frontend/default/blank/template/page/3columns.phtml(59): Mage::getSingleton(’html/head’)
#7 /homepages/28/d214479546/htdocs/scottyvalentine/new_design/app/code/core/Mage/Core/Block/Template.php(144): include(’/homepages/28/d...’)
#8 /homepages/28/d214479546/htdocs/scottyvalentine/new_design/app/code/core/Mage/Core/Block/Template.php(176): Mage_Core_Block_Template->fetchView(’frontend/defaul...’)
#9 /homepages/28/d214479546/htdocs/scottyvalentine/new_design/app/code/core/Mage/Core/Block/Template.php(193): Mage_Core_Block_Template->renderView()
#10 /homepages/28/d214479546/htdocs/scottyvalentine/new_design/app/code/core/Mage/Core/Block/Abstract.php(643): Mage_Core_Block_Template->_toHtml()
#11 /homepages/28/d214479546/htdocs/scottyvalentine/new_design/app/code/core/Mage/Core/Model/Layout.php(515): Mage_Core_Block_Abstract->toHtml()
#12 /homepages/28/d214479546/htdocs/scottyvalentine/new_design/app/code/core/Mage/Core/Controller/Varien/Action.php(326): Mage_Core_Model_Layout->getOutput()
#13 /homepages/28/d214479546/htdocs/scottyvalentine/new_design/app/code/core/Mage/Cms/Helper/Page.php(92): Mage_Core_Controller_Varien_Action->renderLayout()
#14 /homepages/28/d214479546/htdocs/scottyvalentine/new_design/app/code/core/Mage/Cms/controllers/IndexController.php(32): Mage_Cms_Helper_Page->renderPage(Object(Mage_Cms_IndexController), ‘home’)
#15 /homepages/28/d214479546/htdocs/scottyvalentine/new_design/app/code/core/Mage/Core/Controller/Varien/Action.php(349): Mage_Cms_IndexController->indexAction()
#16 /homepages/28/d214479546/htdocs/scottyvalentine/new_design/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(163): Mage_Core_Controller_Varien_Action->dispatch(’index’)
#17 /homepages/28/d214479546/htdocs/scottyvalentine/new_design/app/code/core/Mage/Core/Controller/Varien/Front.php(174): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#18 /homepages/28/d214479546/htdocs/scottyvalentine/new_design/app/Mage.php(447): Mage_Core_Controller_Varien_Front->dispatch()
#19 /homepages/28/d214479546/htdocs/scottyvalentine/new_design/index.php(52): Mage::run()
#20 {main}

Does that mean that the new line won’t work at all or that I have to change something else to make it work?  Does anyone know?  I really appreciate it!  Thanks--

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top