How to convert this simple view to a Phoenix 1.7 view?

Hi all,

I have this very simple 1.6 view I would like to convert to a 1.7 view:

defmodule MyAppWeb.Api.FacetView do
  use MyAppWeb, :view

  def render("facet.json", %{facet: facet}) do
    facet
  end
end

IIUC I have to create a MyAppWeb.FacetJSON module but the render function what should become?

Thank you

defmodule MyAppWeb.SomeView do
  use MyAppWeb, :view

  def render("template_a.html", assigns) do
    …
  end
  def render("template_b.json", assigns) do
    …
  end
end

essentially get

defmodule MyAppWeb.SomeHTML do
  use MyAppWeb, :html

  def template_a(assigns) do
    …
  end
end

defmodule MyAppWeb.SomeJSON do
  def template_b(assigns) do
    …
  end
end
2 Likes