When we worked directly with blocks, it was easy to pass arguments to the block in layout (e.g. default.xml) like:
<block template="..." class="..." name="..."> <arguments> <argument name="foo" xsi:type="string">bar</argument> </arguments> </block>
When now using view models (I know the advantages of using view models), I don't see a way to pass arguments, hence I often need to reject view models and use the block directly again.
Here is how a view model is used:
<block name="orangeco.new.viewmodel" template="OrangeCompany_Catalog::example.phtml"> <arguments> <argument name="view_model" xsi:type="object" shared="[true|false]">OrangeCompany\Catalog\ViewModel\MyNewViewModel</argument> </arguments> </block>
The view model is a shared instance by default (which is good), so in the shared case it doesn't make any sense to pass arguments in the layout. However, I sometimes want to reuse the block type (and the view model type), hence, passing arguments to the view model like we did with blocks would be desirable.
Is there a way to use view models and be able to customize them via arguments from layout?