Php 在Magento中的foreach中获取ChildHTML

Php 在Magento中的foreach中获取ChildHTML,php,magento,Php,Magento,我正在使用Magento中的新模板。为了避免重复代码,我希望对每个产品预览使用相同的子模板 特别是我做了一个这样的展示: $products = Mage::getModel('catalog/product')->getCollection(); foreach ($products as $product) { $this->getChild('preview_product')->setData('product', $product); $thi

我正在使用Magento中的新模板。为了避免重复代码,我希望对每个产品预览使用相同的子模板

特别是我做了一个这样的展示:

$products = Mage::getModel('catalog/product')->getCollection();
foreach ($products as $product) {
      $this->getChild('preview_product')->setData('product', $product);
      $this->getChildHtml('preview_product',true); // true to avoid caching
}
块预览产品调用包含以下代码的文件preview\u product.phtml:

<?php
$product = $this->getData("product");
?>
<h2><?php echo $product->getName(); ?></h2>

问题很简单。这种情况下的结果如下:

<h2>HTC Touch Diamond</h2>
<h2>HTC Touch Diamond</h2>
<h2>HTC Touch Diamond</h2>
HTC触控钻石
钻石
钻石
生成相同的var或相同的html。 如何使用此代码?

替换该行

echo $this->getLayout()
    ->createBlock('core/template')
    ->setTemplate('path/to/template.phtml')
    ->setProduct($product)
    ->toHtml();
$this->getChildHtml('preview_product',true);


为了防止每次都有对象堆积。

第一个示例会产生相同的错误,第二个非常有效!谢谢:)这种方式很有效,但是整页缓存呢?它会缓存这样的东西。。当FPC没有块句柄时,如何将其从FPC中排除
$this->getChildHtml('preview_product',false);