LiveView Basics
A LiveView with Mount
A LiveView using the entry-point mount/1
.
Among other things, here you can assign variables to be used in the template.
Documentation:
https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#c:mount/3
https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html#assign/3
scope "/", LiveViewBasicsWeb do
pipe_through :browser
live "/with-mount", WithMountLive
end
defmodule LiveViewBasicsWeb.WithMountLive do
use LiveViewBasicsWeb, :live_view
def mount(_params, _session, socket) do
socket = assign(socket, :text, "here you can assign variables to be used in the template")
{:ok, socket}
end
def render(assigns) do
~H"""
<Layouts.app flash={@flash}>
<div class="hero">
<div class="hero-content text-center">
<div>
<h1 class="text-4xl font-bold">LiveView Basics</h1>
<h2 class="text-xl">A LiveView with Mount</h2>
<p class="py-6">
A LiveView using the entry-point <code class="bg-base-content text-base-100 px-1">mount/1</code>.
Among other things, {@text}.
</p>
</div>
</div>
</div>
</Layouts.app>
"""
end
end