Open Nek- opened 6 months ago
Hi @Nek- !
Not sure why it would be stupid :) .... but it won't work indeed.
Twig Components are isolated component, somehow like includes
or embed
in Twig.
So the parent()
you're trying to call is not in the "choice_row
" scope, but in the twig:Select
one :)
What you tried is similar to doing something like this :
{# Your template #}
{% block choice_row %}
{{ include('foo.html.twig') }}
{% endblock %}
{# foo.html.twig #}
{{ parent() }}
That would not work, as foo.html.twig
has no parent.
Just beeing curious, what does your "
In my point of view, it's far from obvious that the scope change in the code I give an argument to the component. (Maybe I'm used to ReactJS so it does not feel fluid for me). by stupid code I meant very simple that actually does not work
My twig:Select
is a custom component that renders a fancy select that makes use of JS for some features. It embeds a standard <select>
and updates its values.
I wanted to use it like this because I'm using the component in other contexts that Symfony forms.
Ok! So let's try another way to explain :) How would you do the same thing with an embed tag ? :)
Do you mean this kind of things? (I never used it!)
I think by design embedding will not work with such feature. But it's also because it provides different features, like extending the include. Does the twig component element provide any specific feature that conflicts?
As i tried to explain, TwigComponent are not only twig syntax, they enforce isolation.
What i then tried to tell you is that it's normal it would not work, as it would not work either with embed, and TwigComponent with content are some kind of embeds :)
But i know i'm not always the best to explain my ideas 😅
Hey @Nek- I just created a PR tell me if you think that can be useful 😁 Thanks your report
I tried the following stupid code:
But the
parent()
function does not work inside a twig component. 😅 It was a bit disturbing. Not sure it's a bug or a feature request to be honest.