Embed Eex or Leex Inside Parent Leex Without Spawning a New Process

I am writing an app with many pages using the same format of a table with filtering, sorting, and pagination. I want to extract the shared logic for rendering and event handling of these pages and put it into a separate component, I also need to live redirect based on filtering and sorting. At the moment using Macros I can define callbacks to get the table data from the parent page and inject the required function definitions for handling the sort and filter events. But for render, I don’t know what is the best approach to include my view for the table (which includes click event definitions) in the parent’s render function.

p. s. I am aware I can use nested stateful liveviews and use something like Registery to communicate between parent and child processes and handle redirects like that. To me, it seems too much ceremony and indirection for a simple task and I do not want to take that route if possible.

Welcome around!

Instead of embed, why not just define the other eex/leex and just render it in yours, or via a global one. No need to create a new process or anything for another render? I’m not really understanding what you are doing to be honest though. ^.^;



You are right, for some reason I was not thinking straight! I just rendered the eex template inside the liveview and it is working as expected.


Not sure if you’ve noticed, but José has been working on LiveView components which would solve your exact use case. Have a look at the liveview active branches, I’m on mobile right now and can’t link the WIP

1 Like

Thanks! I wasn’t aware of this! I think this is exactly what I wanted. I will closely follow the development of this brach. Meanwhile, I continue with my not so elegant approach of rendering the child view using render and injecting the shared event handling code using macros.