0

I'm trying to do something similar to this:

include/require php file within phtml template file

I have a .phtml file but need to get the return value from another php file by calling it from said .phtml file. How can this be achieved in Magento 2?

I tried using require, include and require_once with the path relative to the location of the .phtml file but this doesn't work (returns 500 error on page).

To make things somewhat clearer (I'm using a custom module):

  • I have a Settings.php file in a folder called Helper (folder located in root of custom module, so Vendor/Module/Helper)
  • Following, I have a template.phtml file under view/frontend/templates
  • I want to get the return value from a function in Settings.php
  • I have a .phtml file but need to get the return value from another php means ? Could you please share your some code hunt? – Keyur Shah Apr 30 '18 at 8:56
  • @KeyurShah see my updated answer – Bram Apr 30 '18 at 9:00
4

You can call helper in .phtml like,

$helper = $this->helper('YOURNAMESPACE\YOURMODULENAME\Helper\Settings');

Now If you have some function in Settings.php then you can call like,

$helper->getSomethingFromSetting();

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.