I need to call object manager in my phtml file but I don't want to call direct in my file.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
Please suggest
magento2
I need to call object manager in my phtml file but I don't want to call direct in my file.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
Please suggest
Best Answer
You can create one common helper file in your custom module
Content for this file is..
And then you can use
objectManager
in yourphtml
file using this lineContent for this file is..
Now you need to add this class in your layout xml file like this
Here I've added custom block which we have created in custom module instead of using this
Magento\Framework\View\Element\Template
default Magento template Block.Now you can use object manager using this line in your phtml file.
Hope this will help you!