Video Lesson: Pass data to a template using a ViewModel in Magento

Pass data to a template using a ViewModel in Magento

This is premium content

Only available to enrolled or University students.
Join today to unlock all lessons in this course.

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...

Premium content

Enroll to unlock the full content and all course materials.

Maggie

Hey, I'm Maggie! 👋

Ask me anything.

Want to chat with Maggie?

Enroll in this course for AI tutor access.

Comments

Join the discussion!

Comments

Want to comment on this lesson?

Enroll in this course to leave comments.