- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please follow the below URL instruction :
https://blog.qaisarsatti.com/magento_2/magento-2-call-helper-method-in-phtml/
Problem Solved! Click Kudos & Accept as Solution!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please follow the below URL instruction :
https://blog.qaisarsatti.com/magento_2/magento-2-call-helper-method-in-phtml/
Problem Solved! Click Kudos & Accept as Solution!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How call helper in magento 2 PHTML file
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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How call helper in magento 2 PHTML file
you can try that way
- Call directly helper class.
- $helper = $this->helper([Vendor]\[Module]\Helper\Data); $values = $helper->HelperMethod(); $helper = $this->helper([Vendor]\[Module. ..
and second way is
protected $helper;
public function __construct( .... \{Vendor}\{Module}\Helper\Data $helper, .... )
{ .... $this->helper = $helper;
.... }
public function callHelperMethod() {
return $this->helper->getDataFromHelper();
}