Pass data to a template using a ViewModel in Magento
Pass data to a Magento ViewModel template using layout XML arguments and block getData integration.
Lesson Content
We’ve created a view model, but now we need to get access to that ViewModel. We’ll do that by injecting it as an argument to the block using layout XML.
Within view/frontend/layout open the blog post list XML file. Rather than having this block tag be a self-closing tag, open it up.
Within it, create an arguments node that has an argument child node. The name of this argument can be whatever you want. Name it post, but append _vm to the end to signify this is a ViewModel and to avoid ambiguity with posts in your code. This will have an xsi:type of object, and the value of...
Join the discussion!
Comments
Want to comment on this lesson?
Enroll in this course to leave comments.