Video Lesson: Use an after plugin to modify the result of a function in Magento

Use an after plugin to modify the result of a function in Magento

This is premium content

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

Use an after plugin to modify the result of a function in Magento

Learn how to use an after plugin in Magento to conditionally modify controller return templates.

Lesson Content

After plugins are used whenever you want to modify the return value of a function. Let’s say we wanted to modify the template of a specific controller, but only when a specific parameter is passed in. We know we can set a template with layout XML, but if we want to conditionally display a template, it’s better to set the template programmatically within a controller class.

Create a new plugin in the Plugin directory named AlternatePostDetailTemplate.php. Declare strict types, set the namespace to Macademy\BlogExtra\Plugin, and name the class AlternatePostDetailTemplate. We want to h...

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.