在magento上设置家中的自定义页面标题

mjd*_*per 0 magento

我在主页上只展示了一个产品.我想在页面标题中显示产品名称.我怎样才能做到这一点?

alp*_*uri 8

你有多种方法可以做到这一点:

  1. 在模块的布局xml文件中(位于app/design/frontend/[package]/[theme]/layout/{your_file_name} .xml):

    <reference name="head">
        <action method="setTitle"><title>Title text here</title></action>
    </reference>
    
    Run Code Online (Sandbox Code Playgroud)

    这里的坏处是你不能"在飞行中"设置.

  2. 在您的块文件中(_prepareLayout()方法是个好地方):

    public function _prepareLayout() 
    {
        $headBlock = $this->getLayout()->getBlock('head');
        $headBlock->setTitle('Title text here');
        return parent::_prepareLayout();
    }
    
    Run Code Online (Sandbox Code Playgroud)
  3. 其他地方:

    Mage::app()->getLayout()->getBlock('head')->setTitle('Title text here');
    
    Run Code Online (Sandbox Code Playgroud)

有用的链接 - 布局,块和模板