LiveView render not working properly

Hi all,

I have just updated my Phoenix project in order to support LiveView.
I have one problem with the render function:
either I write the render function or I use the naming convention to take the html.leex file I receive the same error:

expected MyWebApp.LayoutView to return a %Phoenix.LiveView.Rendered{} struct
Ensure your render function uses ~L, or your eex template uses the .leex extension.

Got:

    {:safe, ["<main role=\"main\" class=\"container\">\r\n  <p class=\"alert alert-info\" role=\"alert\"\r\n    phx-click=\"lv:clear-flash\"\r\n    phx-value-key=\"info\">", "", "</p>\r\n\r\n  <p class=\"alert alert-danger\" role=\"alert\"\r\n    phx-click=\"lv:clear-flash\"\r\n    phx-value-key=\"error\">", "", "</p>\r\n\r\n", ["<h1>Memorize This:</h1>\n"], "</main>\r\n"]}

my render function

@impl true
  def render(assigns) do
    ~L"""
    <h1>Memorize This:</h1>
    """
  end

any suggestion?

Thanks in advance

You might not have completed all the necessary steps to make the update…

Maybe You can show your router file… it needs something like

plug :put_root_layout, {YourAppWeb.LayoutView, :root}

Try to build a live view project and check the configuration diff with yours

I have put this code following the hex doc:

plug :put_root_layout, {MyAppWeb.LayoutView, :root}

Does this root file has leex extension?

Yes, in addition my root page works properly… It is a normal View, not LiveView. When I put on the URL the other one (that is /cache), I see the error above. But again, the main page works fine

Solved! My live template didn’t have the leex extension it was live.html.eex

Thanks anyway !

2 Likes