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.

asked Feb 13, 2016 at 23:16

2 Answers 2

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.

answered Feb 14, 2016 at 16:33
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

answered Feb 13, 2016 at 23:28
1
  • Thank you, you helped me to understand the nature of the error. Commented Feb 14, 2016 at 16:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.