# Core template events not dispatching in ajax

**URL:** <https://forum.mautic.org/t/core-template-events-not-dispatching-in-ajax/34516>\
**Category:** Development\
**Created:** [December 23, 2024, 10:47am UTC](https://forum.mautic.org/t/core-template-events-not-dispatching-in-ajax/34516 "2024-12-23T10:47:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [December 23, 2024, 10:47am UTC](https://forum.mautic.org/t/core-template-events-not-dispatching-in-ajax/34516/1 "2024-12-23T10:47:48Z")

</div>

Hi.

this goes for Mautic 5, in Mautic 4 we did not have that problem.

I am building a plugin and I noticed when page content is loaded via ajax CoreBundle/CommonController-\>ajaxAction is not dispatching

```auto
CoreEvents::VIEW_INJECT_CUSTOM_CONTENT
CoreEvents::VIEW_INJECT_CUSTOM_TEMPLATE

```

and as a result if you override core templates and then go and load page by going directly to url of the page modifications are visible, but if you visit page via menu on the left, modifications disappear, because default template is loading.

I can fix that, but before I do, I would just like to know if there is a specific reason why ajaxAction is not dispatching events.

Thank you.

Best, M.

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [December 23, 2024, 7:51pm UTC](https://forum.mautic.org/t/core-template-events-not-dispatching-in-ajax/34516/2 "2024-12-23T19:51:49Z")

</div>

Hey, can you be more specific what Mautic 5 version do you use? Is it Mautic 5.1.0? I can see this fix: [Updated CommonController::delegateView to include "mauticTemplate" value in "mauticTemplateVars" for rendering by shinde-rahul · Pull Request #13509 · mautic/mautic · GitHub](https://github.com/mautic/mautic/pull/13509)

---

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [December 23, 2024, 8:35pm UTC](https://forum.mautic.org/t/core-template-events-not-dispatching-in-ajax/34516/3 "2024-12-23T20:35:10Z")

</div>

Thank you for your reply.

Original version was 5.1.0. I did look at the source of 5.2,0, but I dd not actually test it if it would trigger the events for ajax based request (will do that).

Just from looking into the code it did not seem like this was fixed on 5.2.0. But let me actually test the thing and get back, to be sure.

Best, M.

---

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [December 24, 2024, 6:16pm UTC](https://forum.mautic.org/t/core-template-events-not-dispatching-in-ajax/34516/4 "2024-12-24T18:16:59Z")

</div>

I have tested this, happens on 5.2.1 as well. I think we need to dispatch events somwhere in ajax version as well.

---

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [January 6, 2025, 6:14pm UTC](https://forum.mautic.org/t/core-template-events-not-dispatching-in-ajax/34516/5 "2025-01-06T18:14:13Z")

</div>

I think i fixed the issue with this PR:

> <https://github.com/mautic/mautic/pull/14434>
>
> eventAwareRenderView: We added this method, because ajax call needs to dispatch …event to give plugins chance to replace templates.
> 
> 
> 
> | Q | A
> | -------------------------------------- | ---
> | Bug fix? (use the a.b branch) | Y
> | New feature/enhancement? (use the a.x branch) | N
> | Deprecations? | N
> | BC breaks? (use the c.x branch) | N
> | Automated tests included? | N
> | Related user documentation PR URL | mautic/user-documentation#... 
> | Related developer documentation PR URL | mautic/developer-documentation-new#... 
> | Issue(s) addressed | Fixes #... 
> 
> 
> 
> \## Description
> 
> In Mautic 5, when you override core template, changes only take an effect if page is not loaded via ajax, that is because when loading page via ajax does not dispatch CoreEvents::VIEW\_INJECT\_CUSTOM\_TEMPLATE. This PR, fixes that
> 
> 
> 
> 
> 
> 
> \---
> \### 📋 Steps to test this PR:
> 
> 
> \[most likely you will have to test this locally\]
> 
> 1. Open this PR on Gitpod or pull down for testing locally (see docs on testing PRs \[here\](https://contribute.mautic.org/contributing-to-mautic/tester))
> 2. Load a plugin that overrides some core template
> 3. Visit a dashboard page.
> 4. Then click on a menu/link that uses custom template
> 5. Mautic should load the custom template.

I am not sure, this line also seems suspicious, I might uncover a bug down the road and end up writing a wrapper for it too, for now it fixed the issue at hand:

> <https://github.com/mautic/mautic/blob/85d98276e2410e6309d229cb2c333c0af8d0f1fe/app/bundles/CoreBundle/Controller/CommonController.php#L325>
