-
-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TwigComponent][LiveComponent] Live attributes forwarding with attribute nesting #1924
Comments
You could use a more direct syntax to avoid the situation you described <twig:Dialog
modal:id="{{ attributes.render('id') }}"
modal:data-live-name-value="{{ attributes.render('data-live-name-value') }}"
modal:data-live-url-value="{{ attributes.render('data-live-url-value') }}"
modal:data-live-props-value="{{ attributes.render('data-live-props-value') }}"
modal:data-live-csrf-value="{{ attributes.render('data-live-csrf-value') }}"
...
I did not understand your use case, and what you want to do... are you rendering the live attributes of your twig:Dialog component on the modal (non live) component ? Little warning there, those attributes should not be considered public (they could change at any time). |
I know that they could change anytime,thats why i want to forward all of them instead of defining manually. At first I missed that the events to emit/dispatch are dynamic,and not always present |
Forward nested attributes, like I said in issue title not sure how that could be more clear :) |
I thought that it would be possible to do something like: {% set modalAttrs = { modal: { ...attributes } } %}
<twig:Dialog
{{ ...modalAttrs }}
/> but this didn't work |
Haha... ok :) Let's pretend my sentence stopped there! {% set modalAttrs = { modal: { ...attributes } } %}
<twig:Dialog
{{ ...modalAttrs }}
/> It could not work as you expect, as this nested notation is a very specific use case, and cannot be implied for everyone. You could manipulate the array of attributes and prefix all key with "modal:" before spreading it i guess. |
ah, that's right, keys are just strings..
too verbose to remap all the attributes :( |
# Not perfect in term of readability but does the job
{% set nested = attributes|reduce((c, v, k) => c|merge({('modal:'~k): v}), {}) %}
<twig:Dialog {{ ... nested }} />
# Or if the order has no importance..
{% set nested = attributes|reduce((c, v, k) => {('modal:'~k): v, ...c}, {}) %}
<twig:Dialog {{ ... nested }} />
|
I have a live form and a other custom component which wraps dialog component and is opened by live action and is also live.
Dialog accepts nested attributes via
modal:*
properties and I need to forward live attributes to thatmodal:*
part.For example:
How could I forward all
data-live
attributes? Would like to avoid this:The text was updated successfully, but these errors were encountered: