# What is Mautic 5 way of injecting custom templates

**URL:** <https://forum.mautic.org/t/what-is-mautic-5-way-of-injecting-custom-templates/29846>\
**Category:** Development\
**Created:** [November 6, 2023, 9:57pm UTC](https://forum.mautic.org/t/what-is-mautic-5-way-of-injecting-custom-templates/29846 "2023-11-06T21:57:28Z")\
**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:** [November 6, 2023, 9:57pm UTC](https://forum.mautic.org/t/what-is-mautic-5-way-of-injecting-custom-templates/29846/1 "2023-11-06T21:57:28Z")

</div>

Hi,

I am trying to migrate one plugin from Mautic 4 and Mautic 5, I basically fixed everything except the replacing of custom templates.

Now in Mautic 4 we replaced the templates by subscribing like this:

```auto
public static function getSubscribedEvents()
    {
        return [
            CoreEvents::VIEW_INJECT_CUSTOM_TEMPLATE => [
                ['replaceTemplates', 0],
            ],
        ];
    }

```

The thing I have inspected the code base of Mautic. This event is not dispatched anywhere anymore, in fact `CoreEvents::VIEW_INJECT_CUSTOM_TEMPLATE` only occurs twice in the code base.

How would one replace the templates now (maybe Kernel::VIEW)?

Thanks.

---

<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:** [November 24, 2023, 3:13pm UTC](https://forum.mautic.org/t/what-is-mautic-5-way-of-injecting-custom-templates/29846/2 "2023-11-24T15:13:39Z")

</div>

Great question! That was part of the [PhpEngine](https://github.com/mautic/mautic/blob/4a925a913b079f57ddd40d3153f540b92b6ea292/app/bundles/CoreBundle/Templating/Engine/PhpEngine.php#L103). PHP templates were dropped in Symfony 4. So Mautic 5 had to drop the support for it as well in order to run on supported Symfony version.

I guess nobody noticed that the `CoreEvents::VIEW_INJECT_CUSTOM_TEMPLATE` event is no longer triggered anywhere.

`KernelEvents::VIEW` looks like the next best thing. I couldn’t find any events dispatched by the Twig dependencies.

I’ll create a PR to remove this dead code and document it in the upgrading doc.

---

<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:** [November 24, 2023, 3:25pm UTC](https://forum.mautic.org/t/what-is-mautic-5-way-of-injecting-custom-templates/29846/3 "2023-11-24T15:25:47Z")

</div>

Actually, I may have found a place where it could work as before. Would you mind giving it a test?

> <https://github.com/mautic/mautic/pull/12924>
>
> \<!-- ## Which branch should I use for my PR?
> 
> Assuming that:
> 
> a = current ma…jor release
> b = current minor release
> c = future major release
> 
> \* a.x for any features and enhancements (e.g. 5.x)
> \* a.b for any bug fixes (e.g. 4.4, 5.1)
> \* c.x for any features, enhancements or bug fixes with backward compatibility breaking changes (e.g. 5.x) --\>
> 
> | Q | A
> | -------------------------------------- | ---
> | Bug fix? (use the a.b branch) | \[y\]
> | New feature/enhancement? (use the a.x branch) | \[\]
> | Deprecations? | \[\]
> | BC breaks? (use the c.x branch) | \[\]
> | Automated tests included? | \[\] 
> | Related user documentation PR URL | mautic/mautic-documentation#... 
> | Related developer documentation PR URL | mautic/developer-documentation#... 
> | Issue(s) addressed | Fixes https://forum.mautic.org/t/what-is-mautic-5-way-of-injecting-custom-templates/29846/2
> 
> \<!--
> Additionally (see https://contribute.mautic.org/contributing-to-mautic/developer/code/pull-requests#work-on-your-pull-request):
> - Always add tests and ensure they pass.
> - Bug fixes must be submitted against the lowest maintained branch where they apply
> (lowest branches are regularly merged to upper ones so they get the fixes too.)
> - Features and deprecations must be submitted against the "4.x" branch.
> \--\>
> 
> \#### Description:
> 
> \<!--
> Please write a short README for your feature/bugfix. This will help people understand your PR and what it aims to do. If you are fixing a bug and if there is no linked issue already, please provide steps to reproduce the issue here.
> \--\>
> 
> \#### Steps to test this PR:
> 
> \<!--
> This part is really important. If you want your PR to be merged, take the time to write very clear, annotated and step by step test instructions. Do not assume any previous knowledge - testers may not be developers.
> \--\>
> 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. 
> 
> \<!--
> If you have any deprecations, list them here along with the new alternative.
> If you have any backwards compatibility breaks, list them here.
> \--\>

---

<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:** [November 24, 2023, 4:28pm UTC](https://forum.mautic.org/t/what-is-mautic-5-way-of-injecting-custom-templates/29846/4 "2023-11-24T16:28:06Z")

</div>

I will give it a test ASAP. Thank you. Will let you know when I make a review.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/1X/43c63600fe51440378769136903f1fa2a9a34102.png) [@system](https://forum.mautic.org/u/system)\
**Post date:** [November 26, 2023, 4:28am UTC](https://forum.mautic.org/t/what-is-mautic-5-way-of-injecting-custom-templates/29846/5 "2023-11-26T04:28:25Z")

</div>

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.
