在 magento 小部件中的 Block / phtml 模板中设置页面标题、元描述和关键字
我为制造商创建了一个动态登录页面小部件,然后该小部件将创建一个包含类别链接的动态登录页面,仅显示包含该制造商产品的类别。
作为其中的一部分,我尝试使用此代码设置页面标题,
protected function _toHtml()
{
......(build the page logic and stuff)
$head = $this->getLayout()->getBlock('head');
$head->setTitle($title);
$head->setKeywords($keywords);
$head->setDescription($description);
}
但由于某种原因,这不会执行任何操作,因为标题是由调用小部件的页面/cms 页面块设置的。
有什么想法如何做到这一点?
I created a dynamic landing page widget for manufacturers, where the widget would then create a dynamic landing page with links to categories, showing only the categories that are that have products by that manufacturer.
As part of this, I am trying to set the page title using this code
protected function _toHtml()
{
......(build the page logic and stuff)
$head = $this->getLayout()->getBlock('head');
$head->setTitle($title);
$head->setKeywords($keywords);
$head->setDescription($description);
}
But for some reason this doesn't do anything, as the title is set by the page / cms page - block that calls the widget.
Any ideas how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当块的
_toHtml()
被调用时,标题已经被渲染,因此设置它的标题变量没有显着的效果。您需要使用之前执行的方法,例如_prepareLayout()
。By the time your block's
_toHtml()
is called the header has already been rendered so setting it's title variable has no significant effect. You need to use a method that is executed earlier, like_prepareLayout()
.