Where does the render() function come from?

In the Phoenix code below where is the render() function being referenced from? Where is its actual declaration?

defmodule AppxWeb.HelloController do
  use AppxWeb, :controller

  def world(conn, _params) do
    render(conn, "world.html")
  end
end

It is in the Phoenix controller code…

https://hexdocs.pm/phoenix/Phoenix.Controller.html#render/2

2 Likes

To supplement more details…

  1. use AppxWeb, :controller calls the AppxWeb.controller/0 function via AppxWeb.__using__/1 macro.
  2. AppxWeb.controller/0 imports Phoenix.Controller.

Before using Phoenix, learning some basic Elixir is important.

3 Likes

I’m not 100% sure but afaik there’s no “magic” in Phoenix/Elixir, I mean there is no implicit “code injection”.

So the only place where any function that you are using without a Module name (like render here) could only reside in that module itself (in def or defp) or in any module you are explicitly importing or useing. The only exception being functions from the Kernel module where they are imported automatically.

Even aliasing modules still need to call functions with the aliased module name…

I think that this can help better understand how things are tied together in Elixir projects.

The explicitness of Elixir make it very clear. Also this reminds me a recent discussion here in the forum about implicitness vs explicitness… (will update with the link, currently on mobile)

1 Like