1

I can not understand why variable transmission does not work, when the block is called, the display categories on the home page. in the template file I pass a variable to a different template file

list.phtml

<?php $this->getChild('icon_labels')->setData('product', $_product); ?>
<?php echo $this->getChildHtml('icon_labels', false); ?>

if you go into the category of a direct link, then everything works, but if you call category, for example, on the home page

{{Block type = "catalog / product_list" template = "catalog / product / list.phtml" category_id = "52" toolbar_block_name = "product_list_toolbar"}}

I receive an error that Fatal error: Call to a member function setData () on a non-object in \ list.phtml on line

why this error, I can not understand .. I would be grateful for your help. Thank.

2

I replaced this code

<?php $this->getChild('icon_labels')->setData('product', $_product); ?>
<?php echo $this->getChildHtml('icon_labels', false); ?>

on this code in file list.phtml

<?php 
echo Mage::app()->getLayout()->createBlock('core/template')
 ->setData('product', $_product)
 ->setTemplate('catalog/product/icon_labels.phtml')
 ->toHtml(); 
?>

This block in addition, it works well when called list.phtml file from anywhere. And does not require an update of the layout.

1

on the category page, the icon_labels block seems to be added due to a layout update.

but with the {{Block type = "catalog / product_list" template = "catalog / product / list.phtml" category_id = "52" toolbar_block_name = "product_list_toolbar"}} directive you add only the catalog/product_list block without any child blocks.

So in the phtml the $this->getChild('icon_labels') returns null and thats why you get the error. The Block icon_labels is not added as a child block here.

The block icon_labels is most likely is added in a layout.xml file in your theme. To have access to it in your CMS page you have to add it to the product_list block there first

  • Thank you, you helped me to understand the nature of the error. – ZMage Feb 14 '16 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.