Hi everyone,
I’m currently diving into Elixir and Phoenix, trying to grasp the inner workings of the framework. During my exploration, I came across the generated MyAppWeb module, particularly these two functions:
def controller do
quote do
use Phoenix.Controller,
formats: [:html, :json],
layouts: [html: MyAppWeb.Layouts]
import Plug.Conn
import MyAppWeb.Gettext
unquote(verified_routes())
end
end
def live_view do
quote do
use Phoenix.LiveView,
layout: {MyAppWeb.Layouts, :app}
unquote(html_helpers())
end
end
As far as I understand, these functions define common functionalities for controllers and live views. However, what puzzles me is the difference between use Phoenix.Controller, layouts: [html: MyAppWeb.Layouts] and use Phoenix.LiveView, layout: {MyAppWeb.Layouts, :app}.
In the live_view function, we pass an :app atom to specify which function should be called in the layouts module right? However, in the controller function, there’s no such specification. How do controllers know to call MyAppWeb.Layouts.app? Is it passed by default?
I’d appreciate any insights or explanations on this matter. Thank you!






















