App::ZofCMS::Plugin::NavMaker - ZofCMS plugin for making navigation bars
In your Main Config File or ZofCMS Template:
nav_maker => [ qw/Foo Bar Baz/, [ qw(Home /home) ], [ qw(Music /music) ], [ qw(foo /foo-bar-baz), 'This is the title=""', 'this_is_id' ], ], plugins => [ qw/NavMaker/ ],
In your HTML::Template template:
<tmpl_var name="nav_maker">
Produces this code:
<ul id="nav"> <li id="nav_foo"><a href="/foo" title="Visit Foo">Foo</a></li> <li id="nav_bar"><a href="/bar" title="Visit Bar">Bar</a></li> <li id="nav_baz"><a href="/baz" title="Visit Baz">Baz</a></li> <li id="nav_home"><a href="/home" title="Visit Home">Home</a></li> <li id="nav_music"><a href="/music" title="Visit Music">Music</a></li> <li id="this_is_id"><a href="/foo-bar-baz" title="This is the title=""">foo</a></li> </ul>
The plugin doesn't do much but after writing HTML code for hundreds of navigation bars I was fed up... and released this tiny plugin.
This documentation assumes you've read App::ZofCMS, App::ZofCMS::Config and App::ZofCMS::Template
plugins
plugins => [ qw/NavMaker/ ],
The obvious one is that you'd want to add NavMaker into the list of your plugins.
NavMaker
nav_maker
nav_maker => [ qw/Foo Bar Baz/, [ qw(Home /home) ], [ qw(Music /music) ], [ qw(foo /foo-bar-baz), 'This is the title=""', 'this_is_id' ], ], nav_maker => sub { my ( $template, $query, $config ) = @_; return [ qw/Foo Bar Baz/, [ qw(Home /home) ], [ qw(Music /music) ], [ qw(foo /foo-bar-baz), 'This is the title=""', 'this_is_id' ], ]; }
Can be specified in either Main Config File first-level key or ZofCMS template first-level key. If specified in both, the one in ZofCMS Template will take precedence. Takes an arrayref or a subref as a value. If the value is a subref, it must return an arrayref, which will be processed the same way as if the returned arrayref would be assigned to nav_maker key instead of the subref (see description further). The @_ of the sub will contain the following: $template, $query and $config (in that order), where $template is the ZofCMS Template hashref, $query is the query parameters (param names are keys and values are their values) and $config is the App::ZofCMS::Config object.
@_
$template
$query
$config
The elements of the arrayref (whether directly assigned or returned from the subref) can either be strings or arrayrefs, element which is a string is the same as an arrayref with just that string as an element. Each of those arrayrefs can contain from one to four elements. They are interpreted as follows:
nav_maker => [ qw/Foo Bar Baz/ ], # same as nav_maker => [ [ 'Foo' ], [ 'Bar' ], [ 'Baz' ], ],
Mandatory. Specifies the text to use for the link.
nav_maker => [ [ Foo => '/foo' ], ],
Optional. Specifies the href="" attribute for the link. If not specified will be calculated from the first element (the text for the link) in the following way:
href=""
$text =~ s/[\W_]/-/g; return lc "/$text";
nav_maker => [ [ 'Foo', '/foo', 'Title text' ], ],
Optional. Specifies the title="" attribute for the link. If not specified the first element (the text for the link) will be used for the title with word Visit prepended.
title=""
Visit
nav_maker => [ [ 'Foo', '/foo', 'Title text', 'id_of_the_li' ] ],
Optional. Specifies the id="" attribute for the <li> element of this navigation bar item. If not specified will be calculated from the first element (the text of the link) in the following way:
id=""
<li>
$text =~ s/\W/_/g; return lc "nav_$text";
Plugin sets nav_maker key in {t} ZofCMS template special key, to the generated HTML code, simply stick <tmpl_var name="nav_maker"> whereever you wish to have your navigation.
{t}
Fork this module on GitHub: https://github.com/zoffixznet/App-ZofCMS
To report bugs or request features, please use https://github.com/zoffixznet/App-ZofCMS/issues
If you can't access GitHub, you can email your request to bug-App-ZofCMS at rt.cpan.org
bug-App-ZofCMS at rt.cpan.org
Zoffix Znet <zoffix at cpan.org> (http://zoffix.com/, http://haslayout.net/)
You can use and distribute this module under the same terms as Perl itself. See the LICENSE file included in this distribution for complete details.
LICENSE
To install App::ZofCMS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::ZofCMS
CPAN shell
perl -MCPAN -e shell install App::ZofCMS
For more information on module installation, please visit the detailed CPAN module installation guide.