scoop

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 :folded_hands:

Marked As Solved

cmo

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

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 :sparkles:

chrismccord

chrismccord

Creator of Phoenix

It’s available in the live template. What version are you on?

Where Next?

Popular in Questions Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New

Other popular topics Top

siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30877 112
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43622 214
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

We're in Beta

About us Mission Statement