Phoenix.Controller.render/3

Parsed documentation:
View on GitHub
Renders the given `template` and `assigns` based on the `conn` information.

Once the template is rendered, the template format is set as the response
content type (for example, an HTML template will set "text/html" as response
content type) and the data is sent to the client with default status of 200.

## Arguments

  * `conn` - the `Plug.Conn` struct

  * `template` - which may be an atom or a string. If an atom, like `:index`,
    it will render a template with the same format as the one returned by
    `get_format/1`. For example, for an HTML request, it will render
    the "index.html" template. If the template is a string, it must contain
    the extension too, like "index.json"

  * `assigns` - a dictionary with the assigns to be used in the view. Those
    assigns are merged and have higher precedence than the connection assigns
    (`conn.assigns`)

## Examples

    defmodule MyAppWeb.UserController do
      use Phoenix.Controller

      def show(conn, _params) do
        render(conn, "show.html", message: "Hello")
      end
    end

The example above renders a template "show.html" from the `MyAppWeb.UserView`
and sets the response content type to "text/html".

In many cases, you may want the template format to be set dynamically based
on the request. To do so, you can pass the template name as an atom (without
the extension):

    def show(conn, _params) do
      render(conn, :show, message: "Hello")
    end

In order for the example above to work, we need to do content negotiation with
the accepts plug before rendering. You can do so by adding the following to your
pipeline (in the router):

    plug :accepts, ["html"]

## Views

By default, Controllers render templates in a view with a similar name to the
controller. For example, `MyAppWeb.UserController` will render templates inside
the `MyAppWeb.UserView`. This information can be changed any time by using the
`put_view/2` function:

    def show(conn, _params) do
      conn
      |> put_view(MyAppWeb.SpecialView)
      |> render(:show, message: "Hello")
    end

`put_view/2` can also be used as a plug:

    defmodule MyAppWeb.UserController do
      use Phoenix.Controller

      plug :put_view, MyAppWeb.SpecialView

      def show(conn, _params) do
        render(conn, :show, message: "Hello")
      end
    end

## Layouts

Templates are often rendered inside layouts. By default, Phoenix
will render layouts for html requests. For example:

    defmodule MyAppWeb.UserController do
      use Phoenix.Controller

      def show(conn, _params) do
        render(conn, "show.html", message: "Hello")
      end
    end

will render the  "show.html" template inside an "app.html"
template specified in `MyAppWeb.LayoutView`. `put_layout/2` can be used
to change the layout, similar to how `put_view/2` can be used to change
the view.

`layout_formats/1` and `put_layout_formats/2` can be used to configure
which formats support/require layout rendering (defaults to "html" only).
No suggestions.
Please help! Open an issue on GitHub if this assessment is incorrect.