Questions tagged [viewmodel]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2
votes
2answers
44 views

The correct implementation of the output of subcategories in the main category

i want to display subcategories in the root category, i found this way that works for me. app/design/frontend/[Vendor]/[theme]/Magento_Catalog/templates/category/products.phtml <?php $category =...
1
vote
1answer
17 views

Magento 2 Paginate custom collection using ViewModel

Magento 2 encourages the usage of view models instead of filling the blocks with business logic. A view model is an abstraction of the view exposing public properties and commands. It allows ...
6
votes
2answers
4k views

How to Add a viewModel to a core block?

I am trying to overwrite a core template and add my custom logic using a viewModel as follow: <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
1
vote
1answer
76 views

When ViewModel class need to create in Magento2?

I have followed Magento_Catalog Module and I have found ViewModel folder there. Can anyone please explain when we need to create ViewModel classes when we creating our custom module?
0
votes
1answer
26 views

When use block vs view model?

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

Getting information to an admin view page - block, viewmodel, both, etc

Old time Drupal guy here struggling with how to get data to the presentation layer. I have created ui listing and form components to list and edit records but there seems to be a gap in a process to ...
1
vote
0answers
34 views

Editing breadcrumbs ViewModel method

I am trying to override a method from /vendor/magento/module-catalog/ViewModel/Product/Breadcrumbs.php I get an error Type Error occurred when creating object: Piranha\TagRemover\ViewModel\Product\...
0
votes
0answers
14 views

how to pass view model class argument when call block from static block

<block class="Magento\Store\Block\Switcher" name="store_language" as="store_language" template="Magento_Store::switch/languages.phtml"> <arguments> <argument name="view_model" xsi:type="...
0
votes
2answers
773 views

Knockout.js What is the correct way to reference $parent on js file?

I am new on Knockout.js, especially on how to use it in the Magento way. I create a custom ViewModel with a js file called storepickup-select.js and an HTML template called storepickup-select.html. ...
1
vote
1answer
31 views

Nice way to inject the main block to a viewmodel

We want to follow the best practice to add additional functionality to a block template without "rewriting" (i.e. a DI preference) the block. Is there a nice way to inject the main block (which ...
2
votes
4answers
501 views

Can I and should I call Block methods from its' View Model?

I have a template and should write some logic. I have made a view model and I'm calling it from a template. Should I call block methods from the view model? And if so, how can I do it?
4
votes
2answers
1k views

When it is good to use viewModel ? What is difference between viewModel and Block?

I am bit confuse about using viewModel in Magento. I am not getting exact difference between viewModel and Block. In which case using viewModel is best case? Any help will be appreciated.
1
vote
1answer
752 views

Magento 2 : What is use of observableArray in JS file with knockout JS?

I have checked observableArray word declared in js file at top position. I have been seen this function like this items: ko.observableArray([]). Is this function related to AJAX while response is ...