Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Feedback on page: /guides/v2.4/extension-dev-guide/view-models.html #8493

Closed
@audio-engineer

Description

@audio-engineer

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions