If you recently tried updating your Mautic from 7.0.1 to 7.1.2 and found your site completely offline with a cryptic error about “includeWithEvent” in Twig, you’re not alone. The issue comes from a subtle but critical mismatch between Mautic’s custom Twig extension and an update in Twig itself.
Here’s the deal: Twig versions 3.23.0 up to 3.28.0 changed their core include() function to return a Twig\Markup object instead of a plain string. Mautic’s OverrideIncludeExtension, which overrides Twig’s include, still expects a string return type. This leads to a fatal PHP TypeError that takes down your entire site — including the login page. Not ideal!
The root cause is the method signature in OverrideIncludeExtension::includeWithEvent() set to return a string. But with Twig now potentially returning a Twig\Markup object, PHP rightly complains. The site’s templates fail to render, and you’re stuck locked out.
Try clearing caches? Doesn’t help. Pinning Twig back to 3.23.0? Not clean or secure — Composer blocks it due to vulnerabilities and dependency constraints (like the oneup/uploader-bundle). So what’s the fix?
The quickest community-tested workaround is to cast Twig’s return value to string inside the OverrideIncludeExtension like so:
return (string) CoreExtension::include(...);
This respects Twig’s Markup object’s __toString() method and lets Mautic continue rendering templates without errors. Just remember this fix lives inside app/bundles/CoreBundle/Twig/Extension/OverrideIncludeExtension.php and gets overwritten on the next composer update — so you’ll have to reapply it until an official patch ships.
How should Mautic fix this properly? Either loosen the return type hint to accept Twig\Markup or cast internally to string before returning. Until that happens, users on Composer installs need this manual tweak if they want to run the latest minor release safely.
This update drama shows the fragility of tightly coupled dependencies in open-source projects like Mautic. The good news: the community quickly identified the root cause, shared a practical workaround, and discussed the needed fix.
If you’re self-hosting Mautic and wary of these hiccups, this kind of PHP/Twig gotcha is exactly why hosted platforms like Mailertizer exist — we handle updates and compatibility so you can focus on marketing, not firefighting code.
For the full deep dive and ongoing community updates, check out the original forum discussion here.
Running Mautic but want a smoother ride? Mailertizer keeps you on the latest stable releases with zero hassle — so you avoid breaking your site when dependencies shift under the hood.