Best practice to temporarily move a template element keeping its state #4506
Unanswered
FabienHenon
asked this question in
1. Help
Replies: 1 comment 1 reply
-
Pretty sure you can just dynamically bind x-teleport |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
My use case is that I have a template element, let's say a button:
And I would like to be able to temporarily move it inside another element.
Like
x-teleport
does but with a dynamic target. And if the target changes, the template moves to the new target (and is deleted from the previous one).This template is located inside an Alpine element (
x-data
attribute set) and must be able to handle the scoped$data
.Inside my Alpine element I have several other elements, like this (full version):
And when I click inside an element, the DOM should look like this (let's say I clicked on "Element 1"):
I know I could have the same result by copying the button into each element and handling their visibility separately like this:
But I'll have a lot of elements coming from the user and I don't want to be duplicating this button into each element (furthermore, this won't be a simple button but something more complex).
Anything I could use in Alpine to do something similar?
Or do I have to write my own custom directive and handle the copy of the template myself?
If so, how can I keep the state of the template?
I see the
x-teleport
directive uses these functions:Should I use them too?
Thank you for your help
Beta Was this translation helpful? Give feedback.
All reactions