How to stop a global template from rendering on specific pages

I have the following main template (app.html.eex)

<body class="">
     <%= render MagnifyWeb.PublicSharedView, "_header.html", assigns %>


      <!--<p class="alert alert-info" role="alert"><%= get_flash(@conn, :info) %></p>
      <p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p>
      -->

      <main role="main">
        <%= render @view_module, @view_template, assigns %>
      </main>
  </body>

Which is working great however on my login, register, and couple other views/templates I don’t want to render the header i.e.

<%= render MagnifyWeb.PublicSharedView, "_header.html", assigns %>

How can I do this, in the simplest way

Two ways to go about this

  1. You can simply check for an assign before rendering the header in your app.html.eex. Like
    <%= if assigns[:render_header] do %>
     <%= render MagnifyWeb.PublicSharedView, "_header.html", assigns %>
     <% end %>

Then in the controller function for those routes, you can set :render_header in the assign
Like

conn|>render(template file, render_header: true)
  1. You can have a different layout template (e.g app_no_header.html.eex) for those routes that you don’t want the header to to show. In that template file remove the
    <%= render MagnifyWeb.PublicSharedView, “_header.html”, assigns %>
    and in the controller function for those routes, call
    conn|>put_layout(“app_no_header.html”) … |> render(…)
1 Like

Thanks man that is perfect