Editing/Updating render/2?

Phoenix in Action 1.4 (final) has the following template on p. 176

<h1>New Item</h1>

<%= render("form.html", item: @item, action: Routes.item_path(@conn, :create)) %>

Where is the render/2 function defined?

Templates are compiled into functions in your view. Functions available in your view can be called in your templates.

Okay, suppose I know templates are converted to functions on the view. How would I know whether the function takes 0 args, 1 arg, are 1 million args?

It’s defined by the use MyAppWeb, :view, which will call use Phoenix.View.

You could generate docs and look at the modules defined for your View module. You could start you project with iex -S mix run --no-start and then type MyAppWeb.MyView. and hit tab and it’ll list all the functions for that module with their arity.

These docs cover this stuff in much more detail: https://hexdocs.pm/phoenix/views.html

1 Like

The docs for Phoenix.Template are also useful, as Phoenix.View doesn‘t actually handle any of the template related stuff.

1 Like