如何使用布局xml将我的自定义块放置在Magento中的另一个块中?
首先,我想说的是,我在网上搜索了一整天,却找不到我想要的东西。我也是这里的新手,所以如果我违反了任何规则,请原谅我 我正在尝试开发一个模块,将视频添加到产品页面以及图像。我被困在这个概念中: 如何将块插入现有基块中?例如,在产品页面中,有一个块product.info。在这个街区内有“可用性”、“价格”等。 如何使用模块的布局xml和模板在“可用性”下方和“价格”上方插入自定义块 因此,我尝试使用模块的布局文件实现类似的功能:如何使用布局xml将我的自定义块放置在Magento中的另一个块中?,magento,Magento,首先,我想说的是,我在网上搜索了一整天,却找不到我想要的东西。我也是这里的新手,所以如果我违反了任何规则,请原谅我 我正在尝试开发一个模块,将视频添加到产品页面以及图像。我被困在这个概念中: 如何将块插入现有基块中?例如,在产品页面中,有一个块product.info。在这个街区内有“可用性”、“价格”等。 如何使用模块的布局xml和模板在“可用性”下方和“价格”上方插入自定义块 因此,我尝试使用模块的布局文件实现类似的功能: <catalog_product_view translat
<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\u Catalog\u Block\u Product\u视图才能执行此操作吗
PS:基本上我的目标是在图片旁边列出我的视频。现在,我可以从模块中列出我的视频,但这种情况下不会出现图像。我曾经
<block type="myblock/myblock" name="somename" as="media" template="abc.phtml"/>
因此,我想将我的块附加到现有内容。您可以添加新块,而不是过度现有
<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') ?>
谢谢,我解决了。我不得不重写Mage_目录、块、产品、视图、媒体 在我的类中,我对函数_toHtml函数进行了如下处理:
public function _toHtml()
{
$html = parent::_toHtml();
$html.=$this->getChildHtml('media_video');
return $html;
}
其中“媒体视频”是我的区块。我的布局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>
注意下面代码中的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>
getChildHtml放在哪里?在我的模板中还是在主题的模板文件中?因为我正在尝试创建第三方模块,所以我不应该编辑任何现有文件。