# admin\_menu

Source: https://zotonic.com/docs/2084/admin_menu

URI: https://zotonic.com/id/2084

Language: en



This model holds the admin menu, which is built up by calling each module to add items to the menu.

You can extend the admin menu by observing the <a href="/id/doc_notification_admin_menu" class="doc-reference doc-reference-notification"><code>notification#admin_menu</code></a> notification.

Menu Subgroups
--------------

Create a subgroup with a `#menu_item{}` whose `parent` is the enclosing menu's ID and whose `url` is undefined. Add entries by setting their `parent` to the subgroup's `id`; entries may be contributed by different modules.

The admin dropdown renders subgroups as non-clickable section headings followed by their children. Siblings are ordered by `sort` (ascending). With the default visibility check, an empty subgroup is hidden automatically.

For example, configuration entries use `parent = admin_config_group`, which is a subgroup of `admin_system` provided by `mod_admin_config`.

Menu Item Visibility
--------------------

The `visiblecheck` field of `#menu_item{}` and `#menu_separator{}` controls whether an entry is included in the resulting menu. It accepts the following values:

| Value                             | Description                                                                      |
| --------------------------------- | -------------------------------------------------------------------------------- |
| `undefined`                       | Use the default behavior. A menu item is shown when it has a URL or at least one visible non-separator child. Separators are shown. |
| `true` or `false`                 | Always show or hide the entry.                                                   |
| `{acl, Action, Object}`           | Show the entry when `z_acl:is_allowed(Action, Object, Context)` returns `true`.  |
| `{allof, Checks}`                 | Show the entry when all recursively evaluated checks succeed.                    |
| `{anyof, Checks}`                 | Show the entry when at least one recursively evaluated check succeeds.           |
| `Checks`                          | A list of checks is equivalent to `{allof, Checks}`.                             |
| `fun(() -> boolean())`            | Evaluate a zero-argument visibility function.                                    |
| `fun((z:context()) -> boolean())` | Evaluate a visibility function with the current context.                         |

Checks can be nested. For example, the following entry is visible when the user may use either module:

```erlang
#menu_item{
    id = admin_example,
    parent = admin_structure,
    label = ?__("Example", Context),
    url = admin_example,
    visiblecheck = {anyof, [
        {acl, use, mod_example},
        {acl, use, mod_admin_config}
    ]}
}
```

`visiblecheck` only controls menu visibility. The target controller, model, and event handlers must perform their own authorization checks.

Available Model API Paths
-------------------------

| Method | Path pattern | Description                                                                      |
| ------ | ------------ | -------------------------------------------------------------------------------- |
| `get`  | `/`          | Return the full admin menu tree for the current context (`menu/1`), including nested items, resolved URLs, sorting, and visibility filtering. No further lookups. |
| `get`  | `/menu/...`  | Return the admin menu tree built from `#admin_menu` notifications, filtered by ACL/visible checks and organized into parent-child hierarchy. |

`/+name` marks a variable path segment. A trailing `/...` means extra path segments are accepted for further lookups.

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/2084?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/2084?language=en>)
