scoop
LiveView.JS in live.html.heex?
Hi everybody,
I was looking to have a Tailwind UI navbar and mobile menu with a menu toggle button phx-click={JS.toggle(to: "#mobile-menu")} in live.html.heex.
So I understand LiveView.JS isn’t available in the live template out of the box. I’m guessing that there’s a reason for that. Hence, I haven’t tried setting that up before trying to find this already being done by more skilled people. I very much want it to be “done right”.
Also, as a follow on, if one would go that route I guess one would also like to use handle_event for events from the live template.
Regarding having common callbacks for all live views I think this post hints at a possible solution: Tracking inactivity in a Phoenix LiveView app - #5 by davidmeh.
Wiser people of the community – should one go in this direction at all?
Is there an apparent solution to this?
Feels like there’s an apparent solution but I’m sorry that I haven’t been able to find it.
Thanks in advance for any response and take care ![]()
Marked As Solved
cmo
Hey mate.
One option is to do away with the live.html.heex altogether and create a layout component that you use in your liveviews. The layout component will include your navigation bar and whatever else you want, with the inner content being the page contents.
You can see it talked about here:
Also Liked
scoop
Rookie mistake – resolved by referring to Phoenix.LiveView.JS instead of just JS. Sorry.
Getting a reply from Chris McChord made my day however ![]()
chrismccord
It’s available in the live template. What version are you on?
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








