NAME

HTML::Template::Menu - ease menu items for quick web user interface

SYNOPSIS

   use HTML::Template::Menu;
   
   my $m = new HTML::Template::Menu;
   
   $m->add('/','home');
   $m->add('/contact.html');
   $m->add('http://google.com');
   $m->add('http://titantv.com', 'view tv listings');
   
   print $m->output;

METHODS

new()

name()

Returns name of the menu.

name_set()

Sets name of menu, argument is string.

   my $m = new HTML::Template::Menu;
   $m->name_set('login_menu');

add()

Argument is url or CGI::Application runmode name. Optional argument is a label, (the anchor text).

If the first argument has no funny chars, it is treated as a runmode, instead of a url.

The label is what will appear in the link text, If not provided, one will be made. This is part of what this module does for you. 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.

count()

Takes no argument. Returns count of items in this menu. (Each item is a menu link.)

What the TMPL_VAR MAIN_MENU_CLASS will hold, this is the css name.

Arg is string. Sets the TMPL_VAR MAIN_MENU_CLASS css name. If not provided, one is generated for you.

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.

DEFAULT TEMPLATE

This is the default template:

   <div class="<TMPL_VAR MAIN_MENU_CLASS>"><p>
   <TMPL_LOOP MAIN_MENU_LOOP><nobr><b><a href="<TMPL_VAR URL>">[<TMPL_VAR LABEL>]</a></b></nobr>
   </TMPL_LOOP></p></div>

You can feed your own template with:

   my $m = HTML::Template::Menu->new;
   $m->add('http://cpan.org');

   my $tmpl = HTML::Template->new( scalarref => \q{
   <div class="<TMPL_VAR MAIN_MENU_CLASS>"><p>
   <TMPL_LOOP MAIN_MENU_LOOP><nobr><b><a href="<TMPL_VAR URL>">[<TMPL_VAR LABEL>]</a></b></nobr>
   </TMPL_LOOP></p></div>
   });

   $tmpl->param( MENU_LOOP => $m->loop );

One other way to change it:

   $HTML::Template::Menu::DEFAULT_TMPL = q{
   <div class="<TMPL_VAR MAIN_MENU_CLASS>"><p>
   <TMPL_LOOP MAIN_MENU_LOOP><nobr><b><img src="/gfx/bullet.png"> <a href="<TMPL_VAR URL>">[<TMPL_VAR LABEL>]</a></b></nobr>
   </TMPL_LOOP></p></div>
   };   

ICONS

Each menu item has the TMPL_VAR s set: LABEL, URL, ICON. ICON is a broken down simplification of whatever was in the URL. You may choose to use this to include icons.

For example:

   my $m = HTML::Template::Menu->new;
   $m->add('http://cpan.org');

   my $tmpl = HTML::Template->new( scalarref => \q{
   <div class="<TMPL_VAR MAIN_MENU_CLASS>"><p>
   <TMPL_LOOP MAIN_MENU_LOOP><nobr><b><img src="/icons/<TMPL_VAR ICON>"> 
   <a href="<TMPL_VAR URL>">[<TMPL_VAR LABEL>]</a></b></nobr>
   </TMPL_LOOP></p></div>
   });

   $tmpl->param( MENU_LOOP => $m->loop );

This will create an entry such as:

   <nobr><b>
      <img src="/.icons/cpan.png">
      <a href="http://cpan.org">[Cpan]</a></b></nobr></p>

SEE ALSO

HTML::Template - the excellent HTML::Template module. CGI::Application::Plugin::Menu - spinoff plugin for CGI::Application.

AUTHOR

Leo Charre leocharre at cpan dot org

COPYRIGHT

Copyright (c) 2009 Leo Charre. All rights reserved.

LICENSE

This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e., under the terms of the "Artistic License" or the "GNU General Public License".

DISCLAIMER

This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the "GNU General Public License" for more details.