How do I get the query string params on app.html.heex layout?

I have a url like /users?store_id=xyz and I would like to access @conn.params[“store_id”] in the header. However that doesn’t work on a liveview, I get error key :conn not found ...

I tried to get them from @socket, but in the layout the socket.assigns are not there either.

I believe when I have done this before, it’s been via an on_mount call back. You can pull it off the conn and assign_new (via import Phoenix.Component, only: [assign_new: 3]) into the socket.

Oh, actually this was user error. The regular assign to socket in the mount will work, and is available as an @ variable in the app.html.heex layout. My mistake was that I had a branch in a condition that would sometimes set the params but sometimes not.

1 Like