@ macro usage in passing data from conrtoller to template in Phoenix

In the book Programming Phoenix we have this user_controller.ex show action

def show(conn, %{"id" => id}) do
    user = Accounts.get_user(id)
    render(conn, "show.html", user: user)
end

then in show.html.eex you have

<h1>Showing User</h1>
<%= render "user.html", user: @user %>

and finally in user.html.eex

<strong><%= first_name(@user) %></strong> (<%= @user.id %>)

The question is why render “user.html” is using @user instead of just user? Is the controller render function and template render function one and the same?

The @ macro is explained in:
https://hexdocs.pm/eex/EEx.html#module-macros and
https://hexdocs.pm/eex/EEx.SmartEngine.html

3 Likes