It is impossible to handle event from the root template in liveview project?

How can i handle an event from the root template ?

in my root.html.leex, i have this form: `

               <form phx-submit="topic-search" >

                    <input type="text" name="req" placeholder="Search Topics, Posts,..." class="form-control" style="margin-top: 20px"/>

                    <button type="submit"> </button>


i don’t know where i must handle this event.

1 Like

If you are using LiveView, the HTML goes in lib/app_web/live/page_live.html.leex and handle_event goes in lib/app_web/live/page_live.ex

1 Like

yes i agree with you, but my problem is that the HMTL where i work is in lib/app_web/templates\layout\root.html.leex, so basically in this path “lib/app_web/templates\layout” you have just 3 templates :
_ app.html.eex
_ live.html.leex
_ root.html.leex

not like in the live folder where you can put the HTML and .ex files

root is common to liveview and templates, are You sure it should not be in live?

1 Like

when i created my project with “mix phx.nex --live”, root automatically placed to that’s path

Yes, I do not disagree, I just meant root has a different purpose than live, or app.

root contains html tag and is meant to be shared between liveview and normal templates…

The code You show is for liveview, I would not put it inside root, but inside live.


I understand now I put this code in root because I need this bar search on the header to avoid duplicating it multiple times on different live views and sharing it as well.

but, as I understand now from you, I need to write it inside all live views and remove it from root. Yes ?

One possibility is to move the header from root to live, and duplicate the header in app…

But if You don’t use normal templates… it does not really matter.

Although You will need some if You want to authenticate your user.


ok i will try that, thank you very much