3

I use echo in the class file in my extension.

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

How to solve this problem ?

  • Someone suggested me that never echo always return and use log to check the dumpy data. – inrsaurabh Mar 6 '18 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 – Dhaduk Mitesh Mar 6 '18 at 11:41
  • 1
    Plz follow what @prince sir suggested – inrsaurabh Mar 6 '18 at 12:30
2

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

  • 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. – Dhaduk Mitesh Mar 7 '18 at 9:22

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.