Feedback on page: /guides/v2.4/extension-dev-guide/view-models.html #8493
Description
General issue
Description:
Line 3 in the "How to write view models" section is wrong. If $viewModel = $block->getViewModel();
is used in the template to reference to the view model class, it won't work when using <argument name="viewModel">
.
On the other hand, if $viewModel = $block->getData("viewModel");
is used, <argument name="viewModel" xsi:type="object">OrangeCompany\Catalog\ViewModel\MyNewViewModel</argument>
is valid.
Possible solutions:
Line 3 in the example should be replaced with <argument name="view_model" xsi:type="object">OrangeCompany\Catalog\ViewModel\MyNewViewModel</argument>
, OR it should be mentioned that $viewModel = $block->getViewModel();
only works in conjunction with <argument name="view_model" xsi:type="object">OrangeCompany\Catalog\ViewModel\MyNewViewModel</argument>
and that $viewModel = $block->getData("<argument name>");
should be used if another argument name is used.
Additional information:
Tested on Magento 2.4.1