Dancer2::Plugin::Menu - Automatically generate an HTML menu for your Dancer2 app


version 0.009


In your app:

  use Dancer2;
  use Dancer2::Plugin::Menu;

    { title => 'My Parent Item', weight => 3 },
    get 'path' => sub { template },

    { title => 'My Child1 Item', weight => 3 },
    get 'path/menu1' => sub { template },

    { title => 'My Child2 Item', weight => 4 },
    get 'path/menu2' => sub { template },

In your template file:

  <% menu %>

This will generate a hierarchical menu that will look like this when the path/menu1 route is visited:

  <ul><li class="active">Path
      <ul><li class="active">My Child1 Item</li>
          <li>My Child2 Item</li>


This module generates HTML for routes wrapped in the menu_item keyword. Menu items will be injected into the template wherever the <% menu %> tag is located. Child menu items are wrapped in <li> HTML tags which are themselves wrapped in a <ul> tag associated with the parent menu item. Menu items within the current route are given the active class so they can be styled.

The module is in early development stages and currently has few options. It has not been heavily tested and there are likely bugs especially with dynamic paths which are completely untested at this time. The module should work and be adequate for simple menu structures, however.


Wraps a conventional route handler preceded by a required hash reference containing data that will be applied to the route's endpoint.

Two keys can be supplied in the hash reference: a title for the menu item and a weight. The title will be used as the content for the menu items. The weight will determine the order of the menu items. Heavier items (with larger values) will "sink" to the bottom compared to sibling menu items. If two sibling menu items have the same weight, the menu items will be ordered alphabetically.

Menu items that are not endpoints in the route or that don't have a title, will automatically generate a title according to the path segment's name. For example, the route /categories/fun food/desserts is converted to a hierarchy of menu items entitled Categories, Fun food, and Desserts. Note that capitalization is automatically added. Automatic titles will be overridden with endpoint specific titles if they are supplied in a later menu_item call.

If the weight is not supplied it will default to a value of 5.


Add a <% menu %> tag in the appropriate location within your Dancer2 template files. If desired, add css for <li> tags in the active class.




You can find documentation for this module with the perldoc command.

  perldoc Dancer2::Plugin::Menu


The following websites have more information about this module, and may be of help to you. As always, in addition to those websites please use your favorite search engine to discover more resources.

Source Code

The code is open to the world, and available for you to hack on. Please feel free to browse it and play with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull from your repository :)

  git clone git://


You can make new bug reports, and view existing ones, through the web interface at


See perlmodinstall for information and options on installing Perl modules.




Steve Dondley <>


This software is copyright (c) 2018 by Steve Dondley.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.