You can maintain this file and add/remove layouts as you please.
How to modify an existing layout
Petal Pro provides a number of layouts: "sidebar", "stacked" and "public". These are quite configurable however you may want to modify them. To do so, you can simply edit or duplicate the layout file in the following path:
Here you can see the sidebar_layout.ex and stacked_layout.ex files.
Review assigns and adjust your new layout - you can see in layout/1 (core_components.ex) how menu items are passed in as well as the user's name and avatar
When complete, you can import your layout into core_componets.ex and modify the layout/1 function - eg:
4. Now in your template or live view file, you simply update the type to your new layout:
Petal Pro Layouts
Sidebar layout
This is the typical web application layout. It allows for a large number of menu items on the sidebar.
Sidebar layout in action
Sidebar layout on mobile (closed)
Sidebar layout on mobile (open)
Stacked layout
A stacked layout with a navbar and then content.
Stacked layout
Stacked layout on mobile
Stacked layout on mobile with menu open
Public layout
Includes a header and footer - for use in public facing, marketing pages. The public layout is available in router.ex via the :public_layout pipeline:
Light mode
Dark mode
Menus
In menus.ex there is a list of all the menu items. This can be useful when working with navbars and layouts, where you sometimes need to loop over menu items multiple times.
For all menu items, you must define a new get_link/2 function, which takes a name and current_user as the parameters. The name parameter is pattern matched and thus you statically include it in the function definition. A menu item has a name, label, path and icon. Here's an example of a menu item for the "Register" menu item:
You can use the current_user param to conditionally display a menu item. For example, here we don't show the menu item unless the user is an admin.
You can build menu item lists to give to layouts. We define the two core menu lists in menus.ex:
# Public routes
scope "/", PetalProWeb do
pipe_through [:browser, :public_layout]
# Add public controller routes here
get "/", PageController, :landing_page
get "/privacy", PageController, :privacy
get "/license", PageController, :license
live_session :public, layout: {PetalProWeb.Layouts, :public} do
# Add public live routes here
end
end
def get_link(:register, _current_user) do
%{
name: :register,
label: "Register",
path: Routes.user_registration_path(Endpoint, :new),
icon: :clipboard_list
}
end
def get_link(:admin_users = name, current_user) do
if Helpers.is_admin?(current_user) do
%{
name: name,
label: "Users",
path: Routes.admin_users_path(Endpoint, :index),
icon: :users
}
else
nil
end
end