I can call a .phtml file to my .phtml template like a list.phtml.
<?php
echo $this->getLayout()->createBlock('core/template')->setTemplate('goodtest/test.phtml')->toHtml();
?>
But in test.phtml i cannot call $_product values.
For example:
<?php
$_productCollection=$this->getLoadedProductCollection();
foreach ($_productCollection as $_product):
?>
works
<?php echo $_product->getName() ?>
not works:
<?php
echo $this->getLayout()->createBlock('core/template')->setTemplate('goodtest/test.phtml')->toHtml();
?>
In the file: test.html: <?php echo $_product->getName() ?>
.
Do I must load full collection in product again in each included file, how can i get $_product values in test.phtml most effective way?
There are two options:
You can load product by Mage::getModel('catalog/product')->load(<product_id>)
with id each time within foreach loop.
Use below
echo $this->getLayout()->createBlock('catalog/product_list')->setTemplate('goodtest/test.phtml')->toHtml();
instead of
echo $this->getLayout()->createBlock('core/template')->setTemplate('goodtest/test.phtml')->toHtml();
You can assign template through controller like @example
$this->loadLayout();
$listBlock = $this->getLayout()->createBlock('catalog/product_list')
->setTemplate('catalog/product/list.phtml')
->setCollection($collection);
$this->getLayout()->getBlock('content')->append($listBlock);
$this->renderLayout();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.