Magento里面的有些控制器直接就这样设定了title:
$this->loadLayout(); ... $this->getLayout()->getBlock('head')->setTitle($this->__('My Account')); $this->renderLayout();
我们不能直接在layout 里面去修改title,因为这个title在模板文件被解释之前已经设置好了。
怎样去改变不同内页的标题呢? 以下的方法可作参考
这个方法较为简单,就用一个变量(ForcedTitle)来保存页面的title。
在模板文件:page/html/head.phtml 里面,把:
<title>< ?php echo $this->getTitle() ?></title>
改为:
<title> < ?php echo ($this->getForcedTitle()) ? $this->getForcedTitle() : $this->getTitle() ?> </title>
之后,在xml layout 文件里面设定新增的title变量值:
<reference name="head"> <action method="setForcedTitle"><title>Account Dashboard</title></action> </reference>
举例,修改我的帐号页面的layout xml文件:layout/customer.xml
<customer_account> <reference name="head"> <action method=”setForcedTitle”><title>Account Dashboard</title></action> </reference> … </customer_account>