> For the complete documentation index, see [llms.txt](https://docs.petal.build/petal-pro-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.petal.build/petal-pro-documentation/product-docs/fundamentals/layouts-and-menus.md).

# Layouts & Menus

## Layouts

### Sidebar layout

This is the typical web application layout. It allows for a large number of menu items on the sidebar.

```html
<.layout
  current_page={@current}
  type="sidebar"
  current_user_name={user_name(@current_user)}
  main_menu_items={main_menu_items(@current_user)}
  user_menu_items={user_menu_items(@current_user)}
  home_path={home_path(@current_user)}
>
  <.container max_width="xl">
    <div>content</div>
  </.container>
</.layout>e
```

![Sidebar layout in action](/files/jtBg4RMdvU4xk110aB87)

![Sidebar layout on mobile (closed)](/files/Z0wnWn7QbkzUt697cJS2)

![Sidebar layout on mobile (open)](/files/2PVX7BFz6Ml9dzZnBWUJ)

### Stacked layout

A stacked layout with a navbar and then content.

```html
<.layout
  current_page={@current}
  type="stacked"
  current_user_name={user_name(@current_user)}
  main_menu_items={main_menu_items(@current_user)}
  user_menu_items={user_menu_items(@current_user)}
  home_path={home_path(@current_user)}
>
  <.container max_width="xl">
    <div>content</div>
  </.container>
</.layout>e
```

![Stacked layout](/files/WhwW2b8AkrImdy3kgPsf)

![Stacked layout on mobile](/files/0Vq13t9stcSKpVVz4dG5)

![Stacked layout on mobile with menu open](/files/WUkinhr7BvSptnsu6zHI)

## 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:

```elixir
def get_link(:register, _current_user) do
  %{
    name: :register,
    label: "Register",
    path: Routes.user_registration_path(Endpoint, :new),
    icon: :clipboard_list
  }
end
```

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.

```elixir
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
```

You can build menu item lists to give to layouts. We define the two core menu lists in `menus.ex`:

![How layouts use menu lists](/files/QSz9jJQzN028KNDh02wR)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.petal.build/petal-pro-documentation/product-docs/fundamentals/layouts-and-menus.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
