I need to call helper function in PHTML file. I don't know how to do this.
Can anyone help me to achieve this.
Thanks
Solved! Go to Solution.
Please follow the below URL instruction :
https://blog.qaisarsatti.com/magento_2/magento-2-call-helper-method-in-phtml/
Please follow the below URL instruction :
https://blog.qaisarsatti.com/magento_2/magento-2-call-helper-method-in-phtml/
Hello @krishenuetb254
Create a new function in the linked block class :
<?php namespace Vendor\Module\Block; class Test extends \Magento\Framework\View\Element\Template { public function __construct( \Vendor\Module\Helper\Data $helper ) { $this->_helper = $helper; } public function getHelperdata(){ return $this->_helper->helperFunction(); // call your helper function here } }
and call this function in phtml by $block->getHelperdata(); variable.
Hope it helps to resolve your problem
you can try that way
and second way is
protected $helper;
public function __construct( .... \{Vendor}\{Module}\Helper\Data $helper, .... )
{ .... $this->helper = $helper;
.... }
public function callHelperMethod() {
return $this->helper->getDataFromHelper();
}