ykostov
Hello,
Little beginner post here, but I really can’t completely understand the usage of live.html.heex. I will start with what I want to achievе: I want to connect a LiveView socket to my root.html.heex. As I understand from the docs, for this reason live.html.heex is there.
To use the live layout, update your LiveView to pass the :layout option to use Phoenix.LiveView
it might seem obvious to you, but i really can’t figure it out where to update that LiveView, the router or something else?
For instance, if I create a page/index.html.heex I can connect it to its LiveView in the router:
live "/index", IndexLive
then, in IndexLive
defmodule MyAppWeb.IndexLive do
use MyAppWeb, :live_view
def render(assigns) do
render PageView (or smth), "index.html", assigns
end
def mount(params, session, socket) do
(...)
However, this is not the case with live.html.heex.
I want to learn it, don’t what it all ready. Can you recommend me some links to read for this topic, because I really can’t find more in-depth explanations. (there surely is, i just cant find them)
forgot to mention the version used: phoenix 1.6.6
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
cmo
It is worthwhile having a play with the generators to see what code they generate.
IIRC,
live.html.heexwas just a optional template that wrapped the liveview. That is,root.html.heexwas at the top, thenlive.html.heexinside of it, then your page inside of that.This is not the case anymore as
live.html.heexandapp.html.heexwere merged in later versions.The code lives in
MyAppWebthese days, but looks like it might be inMyAppWeb.LayoutViewin older versions.sodapopcan
Have a look in your
lib/my_app_web.exat thedef live_viewline. It seems you are using an older version of Phoenix aslive.html.heexis no longer generated in favour ofapp.html.heexbut it’s the still the same idea. Look in that file for this:This is what gets called when you do
use MyAppWeb, :live_viewand is usinglive.html.heexfor the layout. The layout itself is not a LiveView, just the layout template though you can set assigns for the layout in any LiveView that uses it.If you wanted to have different layouts for different LiveViews you could create another layout in the
layouts/directory and then use it like so:Of course it would be better to define a new helper function in the
MyAppWebmodule as the above won’t include thehtml_helpers/0:then:
Really the best resource for learning this stuff is the official guides. Make sure you look at both Phoenix and LiveView docs and be sure to check out the “GUIDES” tab in each (The MODULES section is more for reference).