mod_menu

Create nested navigation menus for your site.

Activating the module in the admin enables a “menu” item in the admin navigation under “content”, which lets you define a simple menu. Every item in the menu references a Zotonic page and can be looked up using the autocompletion widget.

This menu can be rendered in the frontend with the scomp#menu custom tag.

It will use the _menu.tpl template which is by default able to render a Twitter Bootstrap compatible menu structure using nested <ul> elements.

To implement a different navigation menu, override the _menu.tpl in your project and create new markup.

Domain model

The domain model for this module is the following:

The module creates a new category named menu. This allows one to create multiple menus in a single site. Its edit page in the admin contains the hierarchical menu editor.

The menu resource that is accessible from the admin page (Content > Menu) is the resource with the unique name main_menu.

Accepted Events

This module handles the following notifier callbacks:

  • observe_admin_menu: Add menu management entries to the admin menu.
  • observe_menu_get_rsc_ids: Notifier handler to get all menu ids for the default menu using m_rsc:name_to_id.
  • observe_menu_save: Validate and persist edited menu trees after converting names to resource ids.
  • observe_rsc_get: Normalize stored menu values by converting old tuple formats to #rsc_tree structures.
  • observe_rsc_update: Validate and normalize submitted menu structures during resource updates.
  • observe_rsc_update_done: Rebuild hasmenupart edges after menu changes so referenced resources are tracked correctly.

Delegate callbacks:

  • event/2 with postback messages: ensure_hasmenupart.
  • event/2 with postback_notify messages: <<"menuedit">>.

Edit on GitHub

Observes

Notifications

observe_rsc_get/3

Resource is read, opportunity to add computed fields Used in a foldr with the read properties as accumulator.

Notifications

observe_rsc_update_done/2

An updated resource has just been persisted. Observe this notification to execute follow-up actions for a resource update.

Notifications

observe_rsc_update/3

An updated resource is about to be persisted. Observe this notification to change the resource properties before they are persisted.

Dispatch rules

Dispatch rules

mod_menu dispatch rules

URL dispatch rules defined by mod_menu in apps/zotonic_mod_menu/priv/dispatch/dispatch.

Filters

Filters

menu_expand

Takes a menu, or a menu resource id, and adds all haspart objects connected to the menu ids.

Filters

menu_flat

Flattens the rsc menu structure for use in a template loop.

Filters

menu_ids

Returns all resource ids in a menu. Could return invisible and non existing resource ids. The returned ids are a flat list, the hierarchy of the menu is lost.

Filters

menu_is_visible

Filters a list of menu items on visibility and existance. Only top-level menu items that are both visible and exist are kept in the list. Note that sub-menus…

Filters

menu_rsc

Return the menu to be displayed with a resource.

Filters

menu_subtree

Get the subtree of an id in a menu (if any).

Filters

menu_trail

Return a breadcrumb navigation trail for the given id.

Scomp

Scomp

menu

Show a page menu.

See also

Filters

menu_flat

Flattens the rsc menu structure for use in a template loop.

Filters

menu_subtree

Get the subtree of an id in a menu (if any).

Filters

menu_trail

Return a breadcrumb navigation trail for the given id.

Referred by

Reference

Site configuration

This chapter describes the configuration options for your sites. There’s also global configuration.