Magento gets the current page title using store id or store code

Is there a way to get the current page title by code or store id?

The following code displays the current title of the page but has the currently selected store view, for example http://example.com/it/shop.html , which is the view of a store in Italy.

Context ~ / Model / Controller / Page.php

$title = Mage::getSingleton('core/layout')->getBlock('head')->getTitle();

I'm trying to figure out a way to get the current page title using a specific store code like en

or it

or id. This always results in the Segment.io analytics calling page

out the English text.

+3


source to share


3 answers


Have you tried the code below?



  $page = Mage::getModel('cms/page')->setStoreId(Mage::app()->getStore()->getId())->load('Page-Identifier');

    $pageTitle = $page->getTitle();

      

+1


source


In the context of the phtml file, I think you can only translate a string like:

$this->__($this->getLayout()->getBlock('head')->getTitle())

      



If you want to use a storage transform, you have setTitle

to somewhere in a block class or controller ...

0


source


No, at least not so easy. The name could be set anywhere and it is set as a localized string without any additional information.

Examples of

Category page

The title is set in the block Mage_Catalog_Block_Category_View

if ($headBlock = $this->getLayout()->getBlock('head')) {
    $category = $this->getCurrentCategory();
    if ($title = $category->getMetaTitle()) {
        $headBlock->setTitle($title);
    }

      

Product page

The title is set in the block Mage_Catalog_Block_Product_View

$headBlock = $this->getLayout()->getBlock('head');
if ($headBlock) {
    $product = $this->getProduct();
    $title = $product->getMetaTitle();
    if ($title) {
        $headBlock->setTitle($title);
    }

      

CMS page

The title is set in the block Mage_Cms_Block_Page

$head = $this->getLayout()->getBlock('head');
if ($head) {
    $head->setTitle($page->getTitle());

      

Basket

The title is set to Mage_Checkout_CartController

(not this time!)

$this
    ->loadLayout()
    ->_initLayoutMessages('checkout/session')
    ->_initLayoutMessages('catalog/session')
    ->getLayout()->getBlock('head')->setTitle($this->__('Shopping Cart'));

      

etc. etc.

Unfortunately, there is no single point of connection, you will have to handle all cases separately.

The only common method is Mage_Page_Block_Html_Head::setTitle()

and as stated earlier it is too late because it is already getting the localized string.

Also, as you can see in the examples, sometimes the title is translated text from __()

, and sometimes it is a model attribute in the context of the current repository view.

0


source







All Articles