Questions tagged [viewmodel]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
0answers
14 views

Magento 2.3.5: custom item renderer for checkout review step (access template view model from within uiComponent)

I'm trying to build a custom item renderer intended to gather all configurable child items for an "user-friendlier" display. I finally did it for cart and minicart contexts, but I'm ...
2
votes
1answer
38 views

Pass data or arguments to ViewModel in layout

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="..."> ...
0
votes
1answer
262 views

Magento 2 add ViewModel to product widget

I use ViewModel for custom data in category product listing and everything working ok but i need add ViewModel to widget with new products. Is it possible to add ViewModel to widget? Check my ...
1
vote
1answer
109 views

Magento 2.3.* - How to override ViewModel for override block?

Magento 2.3.* I want to override ViewModel for the override block (custom.block.name). But the issue is my .phtml a file called from the block and it is calling on some condition. Not every time call....
1
vote
1answer
48 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 ...
2
votes
3answers
80 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 =...
0
votes
1answer
39 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
33 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
135 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
1answer
114 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="...
1
vote
1answer
38 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 ...
1
vote
1answer
431 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?
5
votes
2answers
2k 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.
2
votes
4answers
846 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?
0
votes
2answers
1k 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
1k 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 ...
6
votes
2answers
6k 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 follows: <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&...