HOW TO USE VIEW MODEL IN MAGENTO 2

 In Magento blog

In this blog, we are going through how to use the view model in Magento 2.

ViewModel allows passing data and additional functionality to the template file without using a block, or object manager. Use a view model when product data and customer data are required in the front end.

This is the best functionality to pass data and show it in the front end.

⇒ let’s start, first of all, you create this file “default.xml” in this path “app/code/vendorname/ModuleName/view/frontend/layout/

⇒ Then after you create this file “Test.php” in this path “app/code/VendorName/ModuleName/ViewModel/ “.

⇒ then after you create a template file “test.phtml” in this path “app\code\Vendor\Extension\view\frontend\templates\“.

⇒ I hope you understand this blog. if you have any questions let me know in the comment section

Thank You !!

Leave a Comment

0