cancel
Showing results for 
Search instead for 
Did you mean: 

How call helper in magento 2 PHTML file

SOLVED

How call helper in magento 2 PHTML file

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

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How call helper in magento 2 PHTML file

Hi @krishenuetb254 

 

Please follow the below URL instruction :

 

https://blog.qaisarsatti.com/magento_2/magento-2-call-helper-method-in-phtml/

Hope this helps you!
Problem Solved! Click Kudos & Accept as Solution!

View solution in original post

3 REPLIES 3

Re: How call helper in magento 2 PHTML file

Hi @krishenuetb254 

 

Please follow the below URL instruction :

 

https://blog.qaisarsatti.com/magento_2/magento-2-call-helper-method-in-phtml/

Hope this helps you!
Problem Solved! Click Kudos & Accept as Solution!

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

Problem Solved ? Click on 'Kudos' & Accept as Solution ! Smiley Happy

Re: How call helper in magento 2 PHTML file

you can try that way

  1. Call directly helper class.
  2. $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();

}