4

We can define templates and block in layout file, after that we can call block methods in that template file.

My question is

Is there any way to call other block methods in phtml file(template file)?

6

You can call otherblock method inside any template file using below code,

You can pass here your block, instead of Magento\Catalog\Block\Product\ListProduct

      $imageBlock =  $block->getLayout()->createBlock('Magento\Catalog\Block\Product\ListProduct');
      $product=$this->getProducts();
      $imageBlock->getImage($product, 'category_page_list');

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.