How to get `@view_module` from a layout with Phoenix.View 1.0.0

In the template:

<title><%= title(assigns) %></title>

In the view module of the template:

def title(assigns) do
  module = Phoenix.Controller.view_module(assigns.conn)
  template = Phoenix.Controller.view_template(assigns.conn)
  module.title(template, assigns)
end

There’s no need to keep all that logic in the template itself.

4 Likes