Convert String into Literal?

Hello, it is possible to convert a String into Literal ?

# ex. convert "ThermostatLive" in an assigns into ThermostatLive

<%= live_render(@conn, @var) %>

Hi @sabo66 do you mean into an atom? "ThermostatLive" is a literal string, ThermostatLive is a literal atom. Your code doesn’t show any literals it shows an assign which is basically a type of variable.

Converting strings to atoms can be dangerous if they’re based on user specified content. Where is your @var coming from?

@var is coming from the mount of a LiveView
I would render LiveView into another LiveView using a menu and a assign variable (or params ?)

ex. Pet (principal LiveView)
- DogLive
- CatLive
- … (childs LiveView)

  def render(assigns) do
    ~H"""
     <nav>Menu</nav>
      <%= live_render(@socket, @var) %>
    """
  end

  def mount(_params, _sessions, socket) do 
    {:ok, socket |> assign(var: "DogLive")} #DogLive is the default child LiveView
  end

It is very unusual to want to nest liveviews. More commonly you would render different components (live or functional) under the same liveview, or alternatively for navigation it’s more common to have a common Nav component in your app.html.heex file.

1 Like

Hm okay, I’m starting with Phoenix I will see the LiveComponent thx