Skip to content

[TwigBundle] Align TemplateIterator handling of @! original bundle templates with TwigExtension#62810

Merged
nicolas-grekas merged 1 commit intosymfony:6.4from
mbessolov:twigbundle-62730
Dec 19, 2025
Merged

[TwigBundle] Align TemplateIterator handling of @! original bundle templates with TwigExtension#62810
nicolas-grekas merged 1 commit intosymfony:6.4from
mbessolov:twigbundle-62730

Conversation

@mbessolov
Copy link
Copy Markdown
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

@nicolas-grekas
Copy link
Copy Markdown
Member

Thank you @mbessolov.

@nicolas-grekas nicolas-grekas merged commit d8d73c4 into symfony:6.4 Dec 19, 2025
10 of 12 checks passed
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