I am having a situation where I need to instantiate a helper object from my custom module in list.phtml file. For this I have two options either I need to overrride productlist.php and pass the helper class in constructor or use object manager. And I am not satisfied from both of the options.. Can anyone suggest me how can I pass this argument in constructor and use it in my phtml file ? I have read a lot about virtual types and type arguments in di.xml Any help in doing this?
You can try using
ViewModel. The view model is injected into the block via layout XML.
You just add an additional XML argument to the Block class - either when creating the block using
<block> or when referring to the block using
You can go through following articles for more details :