You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, thank you for the great work on the UX Twig Components, which bring a much-needed modern templating experience to Symfony!
I'd like to propose a feature request or open a discussion regarding component context behavior:
Current Behavior
When using the single tag syntax for components (e.g. <MyComponent />), the component does not have access to the parent template’s context. This requires all needed data to be explicitly passed as props:
<MyComponentsomeProp="{{ someParentVar }}" />
However, when using the block/paired syntax, the content inside the component has access to the parent scope:
<MyComponent>
{{ someParentVar }} {# This works #}
</MyComponent>
Feature Request
Would it be possible to make the parent context available (even optionally) to components rendered via the single tag syntax?
This would greatly improve ergonomics for smaller or frequently used components where repeating someProp="{{ someParentVar }}" can be verbose, especially when many variables need to be reused.
Considerations
I understand that component isolation is an intentional design choice, and I'm not suggesting full scope leakage. But perhaps a middle ground could be:
An optional flag on the component class or template to enable access to parent context in single tag mode.
A config-level opt-in for looser isolation (e.g., for internal projects where strict encapsulation isn't required).
Use Case Example
{# in template #}
{% setcolor='blue' %}
<MyComponent />
{# inside MyComponent.html.twig #}
<divstyle="color: {{ color }};">Hello!</div>
Currently, this only works if you pass color explicitly or use block syntax.
The text was updated successfully, but these errors were encountered:
See my comment here, as the RFC and the othen one sum up the current situation perfectly: #2818 (comment)
What you wish for here is very legit and I get the need, as I understand the DX improvment.
I also get why people would fear this very much, for performance, testability and security issues.
So let's wait a bit and we'll decide what and how we can do this. Currently it would be hard to implement properly.
The flag is not in itself a possibility, because the caller must decide what going down, not the opposite :|
And it would also break the Symfony BC promise, as much it would have a big impact on people using the self-closing components for this particular isolation :)
I'd suggest we talk about this topic in a couple of weeks.
Hello Symfony UX Team,
First, thank you for the great work on the UX Twig Components, which bring a much-needed modern templating experience to Symfony!
I'd like to propose a feature request or open a discussion regarding component context behavior:
Current Behavior
When using the single tag syntax for components (e.g.
<MyComponent />
), the component does not have access to the parent template’s context. This requires all needed data to be explicitly passed as props:However, when using the block/paired syntax, the content inside the component has access to the parent scope:
Feature Request
Would it be possible to make the parent context available (even optionally) to components rendered via the single tag syntax?
This would greatly improve ergonomics for smaller or frequently used components where repeating
someProp="{{ someParentVar }}"
can be verbose, especially when many variables need to be reused.Considerations
I understand that component isolation is an intentional design choice, and I'm not suggesting full scope leakage. But perhaps a middle ground could be:
Use Case Example
Currently, this only works if you pass
color
explicitly or use block syntax.The text was updated successfully, but these errors were encountered: