3

I use echo in the class file in my extension.

Magento marketplace not allow echo/print_r/eval().

How to solve this problem ?

3
  • Someone suggested me that never echo always return and use log to check the dumpy data.
    – inrsaurabh
    Mar 6, 2018 at 11:38
  • 1
    Ok, but I use observer and helper and I use an echo in helper file as per my requirement. Any solution ? @SaurabhRanjan Mar 6, 2018 at 11:41
  • 1
    Plz follow what @prince sir suggested
    – inrsaurabh
    Mar 6, 2018 at 12:30

1 Answer 1

3

As per Coding Standard, you should not use echo in block, helper, Model .. etc. Instead of you can create phtml file with your content. And call it in observer like:

public function getProductDetailsHtml(\Magento\Catalog\Model\Product $product)
{
    $html = $this->getLayout()
         ->createBlock('Vendor\Module\Block\Myclass')
         ->setTemplate('Vendor_Module::myfile.phtml')
         ->toHtml();    

    return $html;
}

check this file for more details:

https://github.com/mageprince/magento2-buynow/blob/master/Block/Product/ListProduct.php

1
  • Thank you @prince Patel. This is very useful for me. Till now it is not work in layered navigation. I will try, if not get any solution than ping you. Mar 7, 2018 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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