I need to create a “cart” live view in the root template, I’ve added something like this in
<%= live_render(@conn, CartLive.Cart, id: "cart") %>
So a new live view is started with it’s own process.
The idea is to add elements to the cart from other views, for example from
products_live/products.html.leex . So I tried:
<div phx-click="add-to-shopping-list" phx-value-product="<%= product.name %>" phx-target="cart">
But it doesn’t work.
My initial guess is that
phx-target is just for components, is that correct?
A workaround could be:
- Handle the event in each liveview page and broadcast it using
- Subscribe to
I haven’t tried that, but I guess that it could work. The problem is that I’m not sure is the best way to do it.
Any other idea?