Error messages in template/layout/app

I am pretty new to phoenix. Need some help…
In each form i have the error msg:

<%= if @changeset.action do %>

Oops, something went wrong!
<% end %>

I would like to remove it from each form and put it in the template/layout. How to?
Thanks

You can try and paste this into template/layout.html.eex somewhere (might not work)

<%= if @changeset do %>
  <%= if @changeset.action do %>
    Oops, something went wrong!
  <% end %>
<% end %>

That is, you would need to check if changeset exists in assigns for a given template.

If <%= if @changeset do %> doesn’t work out, try

<%= if changeset = assings[:changeset] do %>
  <%= if changeset.action do %>
    Oops, something went wrong!
  <% end %>
<% end %>

But why would you want that?

I want one place for error messages in some place…
both solutions do not work…
controller!?

I want one place for error messages in some place…

Then you can make a separate view for it, or add a template/render clause to the error view.

both solutions do not work…

Can you provide more info?
Any errors get logged?
What if you replace assings in the second code snippet in my previous post with @conn.assigns?

controller!?

Hm?

Thanks… yep that is working:

<%= if changeset = @conn.assigns[:changeset] do %>
<%= if changeset.action do %>
Oops, something went wrong!
<% end %>
<% end %>

The other solutions throw a 500…
Greetings from Munich