I have something like this. There is probably a much better way of doing it.
defmodule Learnp.LayoutView do
use Learnp.Web, :view
import Learnp.Router.Helpers
def show_notification(conn) do
conn
|> get_flash
|> flash_message
end
def flash_message(%{"info" => message}) do
render "components/_notification.html", class: "primary", message: message
end
def flash_message(%{"error" => message}) do
render "components/_notification.html", class: "danger", message: message
end
def flash_message(_), do: nil
end
And on my templates I can call it with <%= show_notification(@conn)%> and it will render the partial web/templates/layout/components/_notification.html.eex.