How to Fix the Twig includeWithEvent() Error After Updating Mautic from 7.0.1 to 7.1.2

If you recently updated your Mautic instance from version 7.0.1 to 7.1.2 using Composer and suddenly found your site offline with an error message, you’re not alone. This isn’t your average update hiccup — it’s caused by a subtle but impactful change in how Twig, the templating engine Mautic relies on, handles the include() function.

Here’s what’s going on: Twig upgraded their include() method in version 3.28.0 to return a Twig\Markup object instead of a plain string. But Mautic’s override method includeWithEvent() explicitly expects a string return type. That mismatch triggers a PHP TypeError, breaking rendering on all pages—including your login screen.

The kicker? Pinning Twig back to the previous version isn’t a clean or sustainable fix. Composer blocks those older versions due to security concerns, and some of Mautic’s dependencies require newer Twig versions anyway.

Fortunately, a simple trick gets your site back online: casting the Twig return value to a string inside Mautic’s overridden method. Because Twig\Markup implements __toString(), the cast preserves the rendered HTML output exactly as before. This quick edit is done in app/bundles/CoreBundle/Twig/Extension/OverrideIncludeExtension.php by changing return lines to:

return (string) CoreExtension::include(...);

Just clear your cache after editing and your site should come back to life.

However, be warned this fix is overwritten the next time you update Mautic, since it’s a core bundle file managed by Composer. The proper long-term fix needs to be applied in Mautic core — either by relaxing the return type declaration or consistently casting the return value.

What this means for you as a marketer using Mautic: if you’re maintaining your own Composer-based install, keep an eye on this issue and be ready to quickly patch or rollback in case of site downtime after minor upgrades. If you prefer avoiding the headache of troubleshooting broken updates, services like Mailertizer handle these technical updates with care so you don’t have to.

For those who want to dive deeper or follow updates on this problem, here’s the original Mautic community forum discussion.

If you want to skip the trouble of patching core files and wrestling with dependencies, consider hosting your Mautic with Mailertizer — we handle updates and keep your platform stable so you can focus on marketing, not bugs.

Share the Post: