How to configure Symfony UX (Twig & Live Components) in a DDD / Modular project structure #2660
Replies: 1 comment
-
Here is the solution I found : Declare the template path in twig config and use twig namespace in twig_component config twig_component:
anonymous_template_directory: 'components/'
defaults:
App\BoundedContextX\Presentation\Web\Component\:
name_prefix: 'BoundedContextX'
template_directory: '@BoundedContextXComponentTemplates'
App\BoundedContextY\Presentation\Web\Component\:
name_prefix: 'BoundedContextY'
template_directory: '@BoundedContextXComponentTemplates'
App\_Shared\Presentation\Web\Component\:
name_prefix: '_SharedComponent'
template_directory: '@SharedComponentTemplates'
twig:
file_name_pattern: '*.twig'
paths:
'%kernel.project_dir%/src/_Shared/Presentation/Web/Template': Shared
'%kernel.project_dir%/src/_Shared/Presentation/Web/Component': SharedComponentTemplates
'%kernel.project_dir%/src/BoundedContextX/Presentation/Web/Template': BoundedContextX
'%kernel.project_dir%/src/BoundedContextX/Presentation/Web/Component': BoundedContextXComponentTemplates
'%kernel.project_dir%/src/BoundedContextY/Presentation/Web/Template': BoundedContextY
'%kernel.project_dir%/src/BoundedContextY/Presentation/Web/Component': BoundedContextYComponentTemplates |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello 👋
I'm currently trying to integrate Symfony UX (especially Twig and Live Components) into a project that follows a DDD-inspired modular architecture, where each Bounded Context is isolated.
Despite several attempts, I'm struggling to configure twig and twig_component so that Symfony can properly resolve the link between components (PHP classes) and their templates, especially for Live Components.
Here’s a simplified version of my project structure:
In ComponentA.php, I declare the component like this:
And in my twig.yaml, I’ve added:
However, when I render the component via {{ component('context_a.component_a') }}, Symfony throws an error saying that the template is bound to an AnonymousComponent, as if it couldn't match the class with the template.
I've also confirmed the component is registered with the correct tag (live_component) and appears correctly in debug:twig-component.
❓ My question:
What is the correct way to configure Twig paths and UX component discovery in such a modular (DDD-like) structure, so that:
Thank you very much in advance 🙏
Any guidance or best practices from the Symfony UX team or the community would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions