Video Lesson: Exercise: Create a new function within a ViewModel in Magento

This is premium content

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

Exercise: Create a new function within a ViewModel in Magento

Learn how to create a custom ViewModel function in Magento to dynamically display blog post count.

Lesson Content

The idea of ViewModels is to extrapolate all of the logic out of the template. The template is responsible for the presentation of data, not anything else.

Update the hard-coded post count, but instead of passing a list of posts to a count() function in the template, implement this as a custom function on the ViewModel that returns the count.

Note: If you are having trouble seeing the updated changes, try purging the full page cache with: bin/magento cache:clean full_page

When you have finished, check the Source Code tab for the solution.

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.