Feedback on page: /guides/v2.4/extension-dev-guide/view-models.html
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
Hi @audio-engineer. Thank you for your report. To help us process this issue please make sure that you provided sufficient information.
Please, add a comment to assign the issue: @magento I am working on this
- Join Magento Community Engineering Slack and ask your questions in #github channel.
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
Issue confirmed!
@magento I am working on this
@dobooth - Now this PR : #8459 is merged, can we now close this issue as being completed?
Hello, @BarnyShergold. Yes, I think you can close it now. Good that it's fixed now!
Issue closed as completed.
Fixed by #8459