简体   繁体   English

Magento - 如何在观察者中为块设置不同的phtml?

[英]Magento - How can I set a diffrent phtml for a block in an observer?

Here is what I'm trying to do: I need to add a tab on category edit page on the backend (admin panel). 这是我正在尝试做的事情:我需要在后端(管理面板)的类别编辑页面上添加一个选项卡。

I add it from an Observer file this way: 我以这种方式从Observer文件中添加它:

$tabs = $observer->getEvent()->getTabs();
$tabs->addTab('features', array(
              'label'     => Mage::helper('catalog')->__('Related Pages'),
              'content'   => '',
));

The problem is that I do not know how to properly populate the 'content' attribute so I was thinking of getting the "Content" block and manually assigning to it a different phtml file. 问题是我不知道如何正确填充'content'属性,因此我想要获取“Content”块并手动为其分配不同的phtml文件。

Can it be done? 可以吗?

Thanks in advance. 提前致谢。

Try this. 尝试这个。

$tabs->addTab('features', array(
              'label'     => Mage::helper('catalog')->__('Related Pages'),
              'content'   => Mage::app()->getLayout()->createBlock('[module]/[block]')->setTemplate('path/to/template.phtml')->toHtml(),
));

So you need to create you own block that will be rendered by the path/to/template.phtml template. 因此,您需要创建自己的块,该块将由path/to/template.phtml模板呈现。
If you don't need any logic in your template you can skip the creation of the block and use adminhtml/template . 如果模板中不需要任何逻辑,则可以跳过块的创建并使用adminhtml/template Something like this. 像这样的东西。

$tabs->addTab('features', array(
              'label'     => Mage::helper('catalog')->__('Related Pages'),
              'content'   => Mage::app()->getLayout()->createBlock('adminhtml/template')->setTemplate('path/to/template.phtml')->toHtml(),
));

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

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