简体   繁体   English

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

[英]Setting the page title, meta description and keywords from the Block / phtml template in magento widget

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. 但是由于某种原因,它什么都不做,因为标题是由page / cms page-调用小部件的块设置的。

Any ideas how to do this? 任何想法如何做到这一点?

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. 到块的_toHtml()被调用时,标头已经被渲染,因此设置其title变量不会产生重大影响。 You need to use a method that is executed earlier, like _prepareLayout() . 您需要使用更早执行的方法,例如_prepareLayout()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM