I'm trying to understand the difference between the different render
functions in Phoenix. Specifically, I notice there are several different render
functions in a Phoenix View and a Phoenix Template.
For example, within a Phoenix Controller, it's common to see something like this:
# assume this is UserController
def index(conn, _params) do
users = Repo.all(Users) # let's assume that this gives you all your users
render conn, "index.html", users: users
end
Within the index.html
template associated with this View (i.e. UserView), you can see something like this:
# index.html
<ul>
<%= for user <- @users do %>
<li><%= render "user.html", user: user %></li>
<% end %>
</ul>
# user.html
<p><%= @user.name %></p>
My understanding is that the render
function inside of the index.html
template is compiled to a render
function inside of the UserView
. Also, after digging around in iex
, it seems like the render
function in the UserController
's index action comes from Phoenix.Controller.render/3
.
However, I notice that inside of the default app.html.eex
template file, there's a render function that looks like this:
<%= render @view_module, @view_template, assign %>
This doesn't seem to match the signatures of the previous render functions. Can anyone help explain where this render is coming from and how it works?