在 magento 小部件中的 Block / phtml 模板中设置页面标题、元描述和关键字

发布于 2024-12-21 10:34:59 字数 467 浏览 1 评论 0原文

我为制造商创建了一个动态登录页面小部件,然后该小部件将创建一个包含类别链接的动态登录页面,仅显示包含该制造商产品的类别。

作为其中的一部分,我尝试使用此代码设置页面标题,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红焚 2024-12-28 10:35:00

当块的 _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().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文