Making params available in template

Is there a way to make a param set in the Router available to the App Layout when the page renders. So I have a sidebar that indicates what section a user in in. I would like this sidebar to be part of the App Layout template, but how do you make Socket param available so that the sidebar shows the active page. I see that the live/4 route allows setting private values, but I don’t see where these are accessible.

Related answer: How do I make a dynamic navbar LiveView that is on every page? - #2 by cmo

1 Like

Look at how the modal is generated with the

Take special note to how it usessend_upate.
When using send_update you typically only want to do this with components that manage their own state.

But in short. In your app layout, you have something like
<.live_component module={MyAppWeb.NavSearchComponent} id="search" />

then you can push_update to it like so.

some NavSearchComponent:

  def update_prompt(prompt) do
    send_update(__MODULE__, id: "search", prompt: prompt)

  def render(assigns) do
      <.input placeholder={@prompt} />

Then in some LV I might do this.

NavSearchComponent.update_prompt("Something I wanted to update in the prompt")

Also if all you want to do is to respond to the path of the navigation there may be a simpler approach to this.

1 Like

Thanks for the tip. This will certainly come into play as my layout gets more complex.