0

I'm creating a module using blocks and view models, but when is it better to use view models instead of blocks?

1

You just need a Block if you want to set a template filename dynamically or change something in Block functions like _prepareLayout, apart from that, if your template file is fixed, and you want to get data from some collection or model, you can use ViewModel.

These are two great references about it:

https://magento.stackexchange.com/a/277954/16416

https://devdocs.magento.com/guides/v2.3/extension-dev-guide/view-models.html

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.