I have tried creating a fresh project using LiveView. I am following this tutorial : https://www.youtube.com/watch?v=qpaFivCmJOY. I have followed the installation instruction manual and created a basic controller for my view, that contains a live_render
tag, referencing a LiveView controller.
Template :
<h1>Projects</h1>
<%= live_render(@conn, TodoistHelperWeb.AppController) %>
Normal controller :
defmodule TodoistHelperWeb.PageController do
use TodoistHelperWeb, :controller
def index(conn, _params) do
render(conn, "index.html")
end
end
LiveView controller :
defmodule TodoistHelperWeb.AppController do
use Phoenix.LiveView
def mount(_session, socket) do
{:ok, assign(socket, projects: ["project1"])}
end
def render(assigns) do
TodoistHelperWeb.AppView.render("projects.html", assigns)
end
end
LiveView template :
<%= for project <- @projects do %>
<div><%= project %></div>
<% end %>
The project compiles correctly, everything seems to work, but the @projects
variable cannot be found in the liveview template! If I replace it with a static list, the page is displayed without any errors. Using print statements, I was able to determine that render is properly called, however mount is not.
What did I miss? Did I mess up one of the installation steps?