XF 2.0 Change template through listener

Lukas W.

Well-known member
I've built a listener for the app_pub_renderer_page that checks for a few things and alters the response template if required. However, calling $reply->setTemplateName() doesn't seem to change the template any more. Is the event called too late in the chain to do that?

If so, which event would be better suited? I've seen controller_post_dispatch, but it appears to run on admin templates as well, which I want to avoid.
 
The render page event is too late -- it's for changes to the page container. The inner template has been rendered.

If you want to change what is returned, controller_post_dispatch is probably what you want. You can use an event hint to limit it to a particular controller. Or if it's for a specific action, you can just do a class extension to change the behavior that way.
 
Thanks!

I've used the controller_post_dispatch for now, and limited to my criteria with if ($controller instanceof \XF\Pub\Controller\AbstractController && $reply instanceof \XF\Mvc\Reply\View).
 
Top Bottom