首先我想说的是,我在互联网上搜索了一整天,却找不到我想要的东西。我也是这里的新手,所以如果我违反了任何规则,请原谅我。
我正在尝试开发一个模块,将视频和图像一起添加到产品页面。我陷入了这个概念:
如何将我的块插入到现有的基本块中?例如,在产品页面中,有一个块product.info。在这个块中有"可用性"、"价格"等。如何使用模块的布局xml和模板在"可用性"下方和"价格"上方插入自定义块。
因此,我正试图使用模块的布局文件来实现类似的功能
<catalog_product_view translate="label">
<reference name="content">
<reference name="product.info">
WRITE BLOCK HERE SO THAT MY BLOCK SHOWS BELOW AVAILABLITY
</reference>
</reference>
</catalog_product_view>
这可能吗?或者我必须重写核心类Mage_Catalog_Block_Product_View才能执行此操作吗?
附言:基本上,我的目标是列出我的视频旁边的图像。现在,我可以从模块中列出我的视频,但在这种情况下,图像不会出现。我使用
<block type="myblock/myblock" name="somename" as="media" template="abc.phtml"/>
所以我想把我的块附加到现有的内容上。
在我的课上,我去掉了函数_toHtml,如下所示:
public function _toHtml()
{
$html = parent::_toHtml();
$html.=$this->getChildHtml('media_video');
return $html;
}
其中"media_video"是我的块。我的布局xml文件:
<catalog_product_view translate="label">
<reference name="content">
<reference name="product.info">
<reference name="product.info.media">
<block type="myblock/myblock" name="somename" as="media_video" template="beta/abc.phtml"
before="-"/>
</reference>
</reference>
</reference>
</catalog_product_view>
您可以添加新的块,而不是覆盖现有的块。
<catalog_product_view translate="label">
<reference name="content">
<reference name="product.info">
<block type="myblock/myblock" name="somename" as="media_new" template="abc.phtml"/>
</reference>
</reference>
</catalog_product_view>
在phtml文件中使用以下代码获取新块
<?php echo $this->getChildHtml('media_new') ?>
感谢
注意以下代码中的output="toHtml"
。这将在product.info
部分打印您的块。
<catalog_product_view translate="label">
<reference name="content">
<reference name="product.info">
<block type="myblock/myblock" name="somename" as="media"
template="abc.phtml" output="toHtml" before="-" />
</reference>
</reference>
</catalog_product_view>