Skip to content

Conversation

@mbessolov
Copy link
Contributor

@mbessolov mbessolov commented Dec 18, 2025

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #62730
License MIT

Bug Fix: TemplateIterator not discovering templates with @! namespace prefix

The TemplateIterator (used by the cache warmer) was not discovering templates registered with the @! namespace prefix, even though TwigExtension registers them with the Twig loader. This caused incomplete cache warming for templates referenced as @!BundleName/template.twig during cache:warmup, requiring additional compilation at runtime.

Example:

// Both are valid in Twig:
$this->render('@Foo/index.html.twig');   // Uses override if exists, otherwise bundle template
$this->render('@!Foo/index.html.twig');  // Always uses original bundle template

Before: Only @Foo/index.html.twig was compiled during cache:warmup
After: Both @Foo/index.html.twig and @!Foo/index.html.twig are compiled during cache:warmup

The fix adds one line to match the behavior of TwigExtension::load():

$templates[] = $this->findTemplatesInDirectory($bundleTemplatesDir, '!'.$name);

Tests: Updated TemplateIteratorTest to verify templates with the @! prefix are included.
Verified: Fix was also tested on the original bug reproducer: https://github.com/mbessolov/twig-override-cache-reproducer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants