Fix EZP-23332: Avoid warning in LegacyEngine Templating (take 2)

Fixes https://jira.ez.no/browse/EZP-23332

It was previously fixed with https://github.com/ezsystems/ezpublish-kernel/pull/988 but @patrickallaert suggests a better aproach