NAME
CGI::Application::Plugin::PageLookup::Menu - Support for consistent menus across a multilingual website
VERSION
Version 1.4
DESCRIPTION
The CGI::Application::Plugin::PageLookup::Loop module can be used to create a database driven menu and similarly data driven site map page. However the Loop module can only translate into other languages if the URLs are kept the same apart from a language identifier. This means that the website would have search engine friendly in only one language. The CGI::Application::Plugin::PageLookup::Href module could be used to create a static menu and site map that is automatically translated into various languages with search engine friendly URLs. However they cannot be combined as you cannot pass through first the Loop and then the Href. What this module offers is a specialised variant of the Loop smart object that does combine these features. This module depends on CGI::Application::Plugin::PageLookup.
SYNOPSIS
In the template you might define a menu as follows (with some CSS and javascript to make it look nice):
<ul>
<TMPL_LOOP NAME="menu.structure('title')">
<li>
<a href="<TMPL_VAR NAME="this.pageid">"><TMPL_VAR NAME="this.title"></a>
<TMPL_IF NAME="this.structure('title')">
<ul>
<TMPL_LOOP NAME="this.structure('title')">
<li>
<a href="/<TMPL_VAR NAME="this.pageid">"><TMPL_VAR NAME="this.title"></a>
<TMPL_IF NAME="this.structure('title')">
<ul>
<TMPL_LOOP NAME="this.structure('title')">
<li>
<a href="/<TMPL_VAR NAME="this.pageid">"><TMPL_VAR NAME="this.title"></a>
</li>
</TMPL_LOOP>
</ul>
</TMPL_IF>
</li>
</TMPL_LOOP>
</ul>
</TMPL_IF>
</li>
</TMPL_LOOP>
</ul>
and the intention is that this should be the same on all English pages, the same on all Vietnamese pages etc etc. You must register the "menu" parameter as a CGI::Application::Plugin::PageLookup::Menu object as follows:
use CGI::Application;
use CGI::Application::Plugin::PageLookup qw(:all);
use CGI::Application::Plugin::PageLookup::Menu;
use HTML::Template::Pluggable;
use HTML::Template::Plugin::Dot;
sub cgiapp_init {
my $self = shift;
# pagelookup depends CGI::Application::DBH;
$self->dbh_config(......); # whatever arguments are appropriate
$self->html_tmpl_class('HTML::Template::Pluggable');
$self->pagelookup_config(
# load smart dot-notation objects
objects =>
{
# Register the 'values' parameter
menu => 'CGI::Application::Plugin::PageLookup::Menu',
},
);
}
NOTES
This module requires no extra table but it does depend on the 'lineage' and 'rank' columns in the cgiapp_strcuture table. These columns work the same way as they do in the cgiapp_loops table. That is the items are ordered according to the rank column and the lineage column is a comma separated list indicating the ranks of the parent menu items.
The module can be used to get data either for menus or human readable sitemaps.
One value that will always be returned is the 'pageId' column which can be translated into a URL as dictated by the website policy. However due to capitalisation issues, you must either call it 'pageid' in the template or specify 'case_sensitive => 1' somewhere in the template infrastructure.
Use of this module for creating menus and sitemaps rather than the Loop module also means you may not need to set 'globalvars => 1' in the template infrastructure.
You can specify additional columns from the cgiapp_pages table to be included the parameters. These could include a title, may be some javascript etc. These columns are not specified in the core database spec.
In the synopsis all parameters below the headline structure call were shown as being "this dot something". In accordance with HTML::Template::Plugin::Dot this can be changed by using ":" notation. This has not actually been tested yet. Nor have we tried testing varying the arguments at different levels of the menu structure.
FUNCTIONS
new
A constructor following the requirements set out in CGI::Application::Plugin::PageLookup.
structure
This function is specified in the template where additional columns are specified. If no arguments are specified only the 'pageId' column is returned for each menu item. Additional arguments should be specified as a single comma separated string.
__populate_lower_loops
A private function that does what is says.
AUTHOR
Nicholas Bamber, <nicholas at periapt.co.uk>
BUGS
Please report any bugs or feature requests to bug-cgi-application-plugin-pagelookup at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-Application-Plugin-PageLookup. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
AUTOLOAD
AUTOLOAD is quite a fraught subject. There is probably no perfect solution. See http://www.perlmonks.org/?node_id=342804 for a sample of the issues.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc CGI::Application::Plugin::PageLookup::Menu
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=CGI-Application-Plugin-PageLookup
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
http://cpanratings.perl.org/d/CGI-Application-Plugin-PageLookup
Search CPAN
http://search.cpan.org/dist/CGI-Application-Plugin-PageLookup/
ACKNOWLEDGEMENTS
COPYRIGHT & LICENSE
Copyright 2009 Nicholas Bamber.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.