Hi! I’m trying to convert a nested layout structure from pre-1.7 to the new version with a little trouble…
Let’s imagine you have the following layout structure:
layouts
|_ root.html.heex
|_ app.html.heex
|_ admin.html.heex
As per usual, app and admin is rendered inside root…
Now, imagine I have a second layout called settings that should be nested inside admin, for instance:
admin.html.heex
|-> settings.html.heex
|-> profile.html.heex
|-> options.html.heex
In this case, settings should be under the admin layout and profile + options are the pages that should be rendered inside settings. Previously we used render_layout
extensively, but now I’m not exactly sure what is the best approach here.
An example of what worked previously:
settings.html.heex
<%= render_layout LayoutsView, "admin.html" do %>
<%= @inner_content %>
<% end %>
profile.html.heex
<%= render_layout LayoutsView, "settings.html" do %>
Hello From Profile!!!
<% end %>
Is the alternative to render_layout
just calling components directly now? For instance:
ProfileController.ex
put_layout(conn, html: {MyAppWeb.Layouts, :settings})
Layouts.ex
def settings(assigns) do
# Need to pass this so admin can render stuff like
# <.flash_group flash={@flash} />
# But this approach seems a bit off
extra = assigns_to_attributes(assigns)
assigns = assign(assigns, :extra, extra)
~H"""
<.admin {@extra}>
<%= @inner_content %>
</.admin>
"""
end