NAME
CGI::Application::Plugin::Menu - manage navigation menus for cgi apps
SYNOPSIS
use base 'CGI::Application';
use CGI::Application::Plugin::Menu;
sub _set_menus_in_template {
my $self = shift;
my $m = $self->menu('main');
$m->add('home','home page');
$m->add('view_stats');
$m->add('http://cpan.org','visit cpan');
$m->name; # returns 'main', for this example
# GETTING THE HTML TEMPLATE LOOP
my $main_menu_loop = $m->loop;
my $tmpl = $self->this_method_returns_HTML_Template_object;
$tmpl->param( 'MAIN_MENU' => $main_menu_loop );
#or
$tmpl->param( 'MAIN_MENU' => $self->menu_get('main_menu')->loop );
# IN YOUR HTML TEMPLATE:
#
# <ul>
# <TMPL_LOOP MAIN_MENU>
# <li><a href="<TMPL_VAR URL>"><TMPL_VAR LABEL></a></li>
# </TMPL_LOOP>
# </ul>
return 1;
}
DESCRIPTION
This is a simple way ot having menus in your cgi apps.
METHODS
menu()
if you don't provide an argument, the default is used, which is 'main'. returns "A MENU OBJECT"
menus()
returns array ref of names of menus that exist now. They are in the order that they were instanced
my $m0 = $self->menu('main');
$m0->add('home');
$m0->add('news');
my $m1 = $self->menu('session');
$m1->add('logout');
$m1->add('login_history');
for ( @{$self->menus} ){
my $m = $_;
my $menu_name = $m->name;
my $loop_for_html_template = $m->loop;
}
A MENU OBJECT
Are instances of CGI::Application::Plugin::MenuObject.
METHODS
name()
returns name of the menu.
add()
argument is url or runmode optional argument is label
If the first argument has no funny chars, it is treated as a runmode.
The label is what will appear in the link text If not provided, one will be made. If you have a runmode called see_more, the link text is "See More".
The link will be
<a href="?=$YOURRUNMODEPARAMNAME=$ARG1">$ARG2</a>
So in this example:
$m->add('view_tasks');
The result is:
<a href="?rm=view_tasks">View Tasks</a>
loop()
get loop suitable for HTML::Template object See SYNOPSIS.
output()
If you just want the output with the default hard coded template. The default template code is stored in:
$CGI::Application::Plugin::MenuObject::DEFAULT_TMPL
ADDING MENU ITEMS
my $m = $self->menu_get('main menu');
$m->add('home');
$m->add('http://helpme.com','Need help?');
$m->add('logout');
Elements for the menu are shown in the order they are inserted.
AUTOMATICALLY GENERATING A MENU
See CGI::Application::Plugin::AutoMenuitem
AUTHOR
Leo Charre leocharre at cpan dot org
SEE ALSO
CGI::Application HTML::Template LEOCHARRE::DEBUG