Repository navigation
refactor(templating): add TwigRenderer skeleton - #1980
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A critical active finding shows that the bootstrap can fatally fail on multiple web entry points because it eagerly loads TwigRenderer before Composer's autoloader is registered.
1 open issue
What changed in this PR
Adds the initial Twig templating infrastructure alongside the existing Smarty renderer, including environment configuration, renderer behavior, recursive template-cache cleanup, and focused compatibility tests.
Changes:
- Added configurable Twig environment creation with HTML escaping, undefined-variable handling, debug behavior, and compiled-template caching.
- Added the initial Twig renderer with template lookup, variable handling, control rendering, language-directory support, and validators.
- Updated template-cache flushing to remove nested Twig cache directories and added corresponding tests.
| File | Description |
|---|---|
| tests/src/Common/Templating/TwigEnvironmentFactoryTest.php | Tests Twig environment defaults, escaping, undefined variables, directory filtering, debug behavior, and cache settings. |
| tests/Infrastructure/Common/TwigRendererTest.php | Tests Twig renderer behavior, template lookup, variables, controls, language directories, validation, and caching. |
| tests/Application/Admin/TemplateCacheDirectoryTest.php | Tests removal of Smarty files and nested Twig compiled-template directories. |
| src/Common/Templating/TwigEnvironmentFactory.php | Creates configured Twig environments and filters unavailable template directories. |
| lib/Common/Templating/TwigRenderer.php | Provides the initial Twig implementation of the common TemplateRenderer contract. |
| lib/Common/namespace.php | Loads TwigRenderer through the legacy common namespace bootstrap. |
| lib/Application/Admin/TemplateCacheDirectory.php | Recursively removes compiled template files and nested Twig cache directories. |
Review effort: Lite
JohnVillalovos
force-pushed
the
jlvillal/twig_stage1
branch
from
November 19, 2026 02:59
2a4c541 to
860af4c
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The change has two active moderate findings that reverse the intended template search order, causing later directories to override earlier ones in both added-path handling and initial loader construction.
2 open issues
1 resolved since last review
Review effort: Lite
Add the Twig implementation of TemplateRenderer and the factory that creates its Twig environment. Nothing uses either class yet. TwigEnvironmentFactory creates an environment that escapes output for HTML by default and renders an undefined variable as empty, as Smarty does. Compiled templates are cached in subdirectories of tpl_c/twig, so TemplateCacheDirectory::Flush() now removes subdirectories too. It only deleted files directly in tpl_c, which would have left the Twig cache in place after an administrator cleared the cache. TwigRenderer looks templates up in tpl/ and in the directory of the language that is current when it is created. A directory added later is searched last, as with Smarty. The renderer follows the cache.templates setting. The ?debug query parameter switches the template cache off only in debug mode, so a visitor cannot do it. This is a skeleton: - fetchLocalized() throws. The localized lookup is added together with the first email templates. - a template is rendered under the name it is asked for. Mapping a .tpl name to its .twig file and falling back to Smarty come with the engine selection. The tests pin two behaviours next to those of SmartyRenderer: - variables passed to render() are not kept, unlike with Smarty - a control template does not see the assigned variables, as with Smarty Assisted-by: Claude:claude-fable-5-2
JohnVillalovos
force-pushed
the
jlvillal/twig_stage1
branch
from
November 19, 2026 03:13
860af4c to
2f3d545
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Add the Twig implementation of TemplateRenderer and the factory that creates its Twig environment. Nothing uses either class yet.
TwigEnvironmentFactory creates an environment that escapes output for HTML by default and renders an undefined variable as empty, as Smarty does. Compiled templates are cached in subdirectories of tpl_c/twig, so TemplateCacheDirectory::Flush() now removes subdirectories too. It only deleted files directly in tpl_c, which would have left the Twig cache in place after an administrator cleared the cache.
TwigRenderer looks templates up in tpl/ and in the directory of the language that is current when it is created. A directory added later is searched last, as with Smarty. The renderer follows the cache.templates setting. The ?debug query parameter switches the template cache off only in debug mode, so a visitor cannot do it.
This is a skeleton:
The tests pin two behaviours next to those of SmartyRenderer:
Assisted-by: Claude:claude-fable-5-2