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 Reply

Your email address will not be published. Required fields are marked *


CynoInfotech was founded in 2019, in Ahmedabad, Gujrat. CynoInfotech is a Magento module development company that grow up over this year with outsourcing clients.